大佬教程收集整理的这篇文章主要介绍了带有自定义适配器的Android DrawerLayout和Listview,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
对于listview,我创建了一个自定义适配器,我使用list_item xml文件创建每一行,该文件具有imageview和textview.
该应用程序运行,但当我打开抽屉时,我只看到没有列表视图的背景.
现在,如果我使用ArrayAdapter(默认)尝试它,列表视图就会显示出来.
有什么建议?
我的定制适配器
public class CustomAdapter extends ArrayAdapter<Categories>{ Context context; int layoutresourcEID; Categories[] data = null; public CustomAdapter(Context context,int layoutresourcEID,Categories[] categs) { super(context,layoutresourcEID); this.layoutresourcEID = layoutresourcEID; this.context = context; data = categs; } @Override public View getView(int position,View convertView,ViewGroup parent) { View row = convertView; PHolder holder = null; if(row == null) { LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutresourcEID,parent,falsE); holder = new PHolder(); holder.imgIcon = (ImageView)row.findViewById(R.id.categimagE); holder.txttitle = (TextView)row.findViewById(R.id.categtext); row.setTag(holder); } else { holder = (PHolder)row.getTag(); } Categories categ = data[position]; holder.txttitle.setText(categ.titlE); holder.imgIcon.setImageresource(categ.icon); return row; } static class PHolder { ImageView imgIcon; TextView txttitle; }
}
在我的主要活动中
@H_780_16@mDrawerList = (ListView) findViewById(R.id.categlist); Categories data[] = new Categories[] { new Categories(R.drawable.restaurant,R.String.food),new Categories(R.drawable.bar_coktail,R.String.bar),new Categories(R.drawable.mall,R.String.shop),new Categories(R.drawable.agritourism,R.String.out),new Categories(R.drawable.dance_class,R.String.art),new Categories(R.drawable.officebuilding,R.String.other),new Categories(R.drawable.university,R.String.education),new Categories(R.drawable.townhouse,R.String.housE),new Categories(R.drawable.junction,R.String.transport) }; CustomAdapter ca = new CustomAdapter(this,R.layout.list_item,data); View header = (View)getLayoutInflater().inflate(R.layout.list_header,null); mDrawerList.addHeaderView(header); mDrawerList.setAdapter(ca);
以上是大佬教程为你收集整理的带有自定义适配器的Android DrawerLayout和Listview全部内容,希望文章能够帮你解决带有自定义适配器的Android DrawerLayout和Listview所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。