Ich war für 4 Tage erschöpft, um meine Listview zu scrollen, aber ich konnte nicht und dann schlug jemand RecyclerView zu verwenden, wie ich CoordinatorLayout, also tat ich. Jetzt, nachdem RecyclerView verstanden und implementiert wurde, hat es den gleichen Fehler. es scrollt jetzt nicht was soll ich tun ??? Ich möchte aufgeben. Ich kann nirgendwohin gehen.RecyclerView nicht scrollen
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_contacts_list, container, false);
DataBaseOperations hell = new DataBaseOperations(getActivity());
SQLiteDatabase db = hell.getReadableDatabase();
String[] columns = {mDatabase.Tableinfo.ID,mDatabase.Tableinfo.Contacts_phone,mDatabase.Tableinfo.Contacts_name,mDatabase.Tableinfo.Contact_pic};
Cursor Contacts = db.query(mDatabase.Tableinfo.contacts, columns, null, null, null, null, null);
Toast.makeText(getContext(),"come on"+Contacts.getCount(),Toast.LENGTH_SHORT).show();
RecyclerView contacts = (RecyclerView) view.findViewById(R.id.contacts);
contacts.hasFixedSize();
RecyclerView.LayoutManager llv = new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL,false);
contacts.setLayoutManager(llv);
Context t = getContext();
MyContactsRecyclerViewAdapter lv = new MyContactsRecyclerViewAdapter(Contacts,t);
contacts.setAdapter(lv);
return view;
}
hier ist xml für meine list.xml und es ist in einem Pager sollte ich Code für das auch schreiben ????
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/contacts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:scrollbars="vertical"
tools:listitem="@layout/fragment_contacts" />
Jede Hilfe wäre willkommen. das ist xml für meine MainActivity.
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".mainactivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"
/>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backscreen3"
/>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<!-- content_main doesn't really have anything. -->
</android.support.design.widget.CoordinatorLayout>
Das ist mein RecyclerAdapter.
public class MyContactsRecyclerViewAdapter extends RecyclerView.Adapter<MyContactsRecyclerViewAdapter.ViewHolder> {
private Cursor cursor;
private Context mcontext;
private View view;
public MyContactsRecyclerViewAdapter(Cursor cur, Context con){
cursor = cur;
mcontext = con;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.fragment_contacts, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
cursor.moveToPosition(position);
String nam = cursor.getString(cursor.getColumnIndex(mDatabase.Tableinfo.Contacts_name));
String phon = cursor.getString(cursor.getColumnIndex(mDatabase.Tableinfo.Contacts_phone));
byte[] b = cursor.getBlob(cursor.getColumnIndex(mDatabase.Tableinfo.Contact_pic));
holder.name.setText(nam);
holder.phone.setText(phon);
if (b==null) {
Profile bla = new Profile();
holder.pic.setImageBitmap(bla.getRoundedShape(BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.samplepro),60,60));
} else {
holder.pic.setImageBitmap(BitmapFactory.decodeByteArray(b,0,b.length));
}
}
@Override
public int getItemCount() {
if(cursor != null){
return cursor.getCount();}
return 0 ;
}
public class ViewHolder extends RecyclerView.ViewHolder {
public final View mView;
public TextView name;
public TextView phone;
public ImageView pic;
public ViewHolder(View view) {
super(view);
mView = view;
pic = (ImageView) view.findViewById(R.id.image);
phone = (TextView) view.findViewById(R.id.phone);
name = (TextView)view.findViewById(R.id.name);
}}}
Das ist es. Ich denke, dass alles damit zusammenhängt. Bitte finden ein error.Remember Scroll kommt und verschwindet, aber immer noch kein Scrollen
Ihr Code sieht gut aus, so scheint es gibt ein anderes Problem und kann nicht sagen, was. Können Sie ein Beispielprojekt oder mehr Informationen darüber, wie Sie den Adapter implementiert haben, teilen? –
Überprüfen Sie meine Frage bitte erneut @ MidhunMP –
So Ihre Recycler-Ansicht nicht scrollen oder es ist nachlässig? –