当前位置:  开发笔记 > 数据库 > 正文

RecyclerView不滚动

如何解决《RecyclerView不滚动》经验,为你挑选了0个好方法。

我已经筋疲力尽了4天让我的listview滚动但我不能然后有人建议使用RecyclerView,因为我使用的是CoordinatorLayout所以我做了.现在了解并实施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的xml,它是在寻呼机,如果我也发布代码????


任何帮助,将不胜感激.这是我的MainActivty的xml.



    

        


        
        


    

    




这是我的RecyclerAdapter.

public class MyContactsRecyclerViewAdapter extends RecyclerView.Adapter {

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

        }}}

就是这个.我认为每件事都与之相关.请找一个错误.记住ScrollBars出现并消失,但仍然没有滚动

推荐阅读
爱唱歌的郭少文_
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有