当前位置:  开发笔记 > Android > 正文

只有一个项目显示在回收站视图中

如何解决《只有一个项目显示在回收站视图中》经验,为你挑选了1个好方法。

我在回收站视图中显示所有项目时遇到问题.我的代码只显示一个项目(主页.我有3个项目:主页,浏览照片和我的旅行)

fragment_navigation_drawer.xml



    
    

    

    
    


RecyclerAdapter.java

public class RecyclerAdapter extends RecyclerView.Adapter {
    private LayoutInflater inflater;
    List data = Collections.emptyList();

    public RecyclerAdapter(Context context, List data){
        inflater= LayoutInflater.from(context);
        this.data = data;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=inflater.inflate(R.layout.itemlist,parent,false);
        MyViewHolder holder= new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        MenuList current=data.get(position);
        holder.title.setText(current.title);
        holder.image.setImageResource(current.icon);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }
    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView title;
        ImageView image;
        public MyViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.item_list);
            image =  (ImageView) itemView.findViewById(R.id.icons);
        }
    }
}

NavigationDrawerFragment.java(仅发布与recyclerview相关的代码)

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View layout = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
    recyclerView = (RecyclerView) layout.findViewById(R.id.drawerList);
    adapter = new RecyclerAdapter(getActivity(),getData());
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    return layout;
}

public static List getData(){
    List data = new ArrayList<>();
    String[] titles={"Home","My Travels","Browse Photos"};
    int[] icons ={R.drawable.home,R.drawable.sunglasses,R.drawable.tooltip_image};

    for(int i=0;i<3;i++){
        MenuList current = new MenuList();
        current.title=titles[i];
        current.icon=icons[i];
        Log.d("Data",titles[i]);
        Log.d("Data",""+icons[i]);
        data.add(current);
    }
    return data;
}

itemlist.xml




    

    

我能做的是检查所有传递的数据(一切似乎都没问题).还尝试更改宽度以在我的相对和线性布局中包装内容(fragment_navigation_drawer.xml),但我只是丢失了我的背景颜色,但仍然只显示一个项目.



1> Ravi..:

更改的高度LinearLayout,以wrap_contentitemlist.xml

android:layout_

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