不调用BaseAdapter getView()

时间:2017-04-27 16:17:40

标签: android listview

我想将一个listView添加到ViewPager的视图中 但是没有调用getview()。

enter image description here

请帮助我。这个问题困扰了我几天!

这是主要代码:

class  itemBean{
    int imageid;
    String title;
    void itemBean(int imageId,String Title){
        imageid=imageId;
        title=Title;
    }
}
public void listview1sx(){
    LayoutInflater layoutInflater= LayoutInflater.from(this);
    View view= layoutInflater.inflate(R.layout.view1,null);
    listView=(ListView) view.findViewById(R.id.listview1);
    itemBean fashi = new itemBean();
    fashi.itemBean(R.mipmap.fashi, "法师");
    itembeenlist.add(fashi);
    itemBean fash = new itemBean();
    fash.itemBean(R.mipmap.fashi, "法师");
    itembeenlist.add(fash);
    listView.setAdapter(new MyListViewAdpter(this,itembeenlist));

    Log.d("xyj","i am step out from Adpter!");
}
class viewHolder{
    ImageView imageView;
    TextView textView;
}

MyListViewAdpter:

class MyListViewAdpter extends BaseAdapter{
    private List<itemBean> mlist;
    private LayoutInflater mlayout;
    public MyListViewAdpter(Context context,List<itemBean> list){
        mlayout=LayoutInflater.from(context);
        mlist=list;
    }
    public int getCount() {
        Log.e("xyj","getcount   "+mlist.size());
        return mlist.size();
    }
    public Object getItem(int i) {
        Log.e("xyj","getItem");
        return mlist.get(i);
    }
    public long getItemId(int i) {
        Log.e("xyj","getItemId   "+i);return i;
    }
    public View getView(int i, View view, ViewGroup viewGroup) {
        viewHolder viewHolderr=new viewHolder();
        Log.e("xyj","getView");
        if(view==null){
            view=mlayout.inflate(R.layout.list_item,null);
            viewHolderr.imageView=(ImageView)view.findViewById(R.id.imageitem);
            viewHolderr.textView=(TextView) view.findViewById(R.id.tvitem);
            view.setTag(viewHolderr);
        }
        else{
            viewHolderr=(viewHolder) view.getTag();
        }
        viewHolderr.imageView.setImageResource(mlist.get(i).imageid);
        viewHolderr.textView.setText(mlist.get(i).title);
        return view;
    }
}

1 个答案:

答案 0 :(得分:0)

您没有在构造函数中调用super

public MyListViewAdpter(Context context,List<itemBean> list){
        super(context,list);
        mlayout=LayoutInflater.from(context);
        mlist=list;
    }