2016-01-11 11 views
7

स्क्रॉल करने के लिए मेरी सूचीदृश्य प्राप्त करने के लिए 4 दिनों के लिए समाप्त हो गया है, लेकिन मैं नहीं कर सकता था और फिर किसी ने RecyclerView का उपयोग करने का सुझाव दिया क्योंकि मैं कोऑर्डिनेटरलाइट का उपयोग कर रहा था इसलिए मैंने किया। अब RecyclerView को समझने और कार्यान्वित करने के बाद भी यह वही त्रुटि है। यह अब स्क्रॉल नहीं करता है मुझे क्या करना चाहिए ??? मुझे छोड़ना पसंद है। मेरे पास कहीं नहीं है।रीसाइक्लर स्क्रूइंग

@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; 
} 
यहाँ

मेरी list.xml के लिए एक्सएमएल है और यह एक पेजर में है मैं भी उस के लिए कोड पोस्ट करना चाहिए ????

<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" /> 

किसी भी मदद की सराहना की जाएगी। यह मेरे मुख्य एक्टिविटी के लिए एक्सएमएल है।

<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> 

यह मेरा 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); 

     }}} 

यह है। मुझे लगता है कि इससे संबंधित हर चीज। कृपया एक error.Remember स्क्रॉलबार आता है और गायब हो जाता है, लेकिन अभी भी कोई स्क्रॉल

+0

आपका कोड ठीक दिखता है, ऐसा लगता है कि कुछ और मुद्दा है और यह नहीं बता सकता कि क्या। क्या आप एडाप्टर को कार्यान्वित करने के तरीके के बारे में नमूना प्रोजेक्ट या अधिक जानकारी साझा कर सकते हैं? –

+0

कृपया मेरा प्रश्न फिर से जांचें @MidhunMP –

+0

तो आपका रीसाइक्लर स्क्रॉल नहीं कर रहा है या यह लगी हुई है? –

उत्तर

3

लगता है जैसे आप कि ViewPager साथ <include layout="@layout/content_main" /> में एक समस्या थी (जैसा कि मैंने एंड्रॉयड स्टूडियो पूर्वावलोकन में देखें)

इस तरह यह प्रयोग करें।:

<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="com.example.umerasif.chattris.Chattris"> 


<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme"> 


    <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:tabGravity="fill" 
     app:tabMode="fixed" /> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="470dp" 
     android:layout_weight="1" 
     android:background="@android:color/darker_gray" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 
    <android.support.v4.view.ViewPager 
     android:id="@+id/pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     /> 

    </android.support.v4.widget.NestedScrollView> 
</android.support.design.widget.AppBarLayout> 

यह अब काम करना चाहिए।

+0

के बाहर भी देखें पेजर को थोड़ा बदलकर धन्यवाद, मैंने इसे काम किया है। CoordinatorLayout का उपयोग करते समय लोगों के लिए यहां तक ​​कि सरल स्क्रॉल व्यू के लिए nestedScrollView का उपयोग करें। –

+0

खुशी है कि आपने यह किया है;) आप इस उत्तर को एक सुझाव या एक संपादन भी दे सकते हैं, मैं इसे देख लूंगा और फिर उन लोगों के लिए इसे स्वीकार करूँगा जिनके पास एक ही समस्या थी। – Mohsen

3

AppBarLayout के बाहर ViewPager को स्थानांतरित करने से मेरी समस्या हल हो गई।

+0

इसने मेरा मुद्दा धन्यवाद दोस्त हल किया –

संबंधित मुद्दे