public class MyAdapter extends BaseAdapter{ @Override public int getCount() { return mitems.length;//拿到个数 } @Override public Object getItem(int position) { return mitems[position];//拿个实例 } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = View.inflate(HomeActivity.this,R.layout.home_gv_item,null); ImageView iv = (ImageView) view.findViewById(R.id.iv_item);//切记这里要用view.findViewById!!!! TextView tv = (TextView) view.findViewById(R.id.tv_item);//要加view.不然会报空指针 iv.setImageResource(mPics[position]); tv.setText(mitems[position]); return view;//返回view } }
baseAdapter自定义适配器千万注意
最新推荐文章于 2021-05-25 15:02:23 发布