我有一个扩展ArrayAdapter的类.我无法将listadapter设置为ListVIEw,因为当我尝试创建listadapter时,我不知道代码应该是什么.这是我目前的代码.
class Item { String username; String number; String content; } class listadapter extends ArrayAdapter<Item> { public listadapter(Context context, int textVIEwResourceID) { super(context, textVIEwResourceID); // Todo auto-generated constructor stub } private List<Item> items; public listadapter(Context context, int resource, List<Item> items) { super(context, resource, items); this.items = items; } @OverrIDe public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) { VIEw v = convertVIEw; if (v == null) { LayoutInflater vi; vi = LayoutInflater.from(getContext()); v = vi.inflate(R.layout.List_item, null); } Item p = items.get(position); if (p != null) { TextVIEw tt = (TextVIEw) v.findVIEwByID(R.ID.ID); TextVIEw tt1 = (TextVIEw) v.findVIEwByID(R.ID.categoryID); TextVIEw tt3 = (TextVIEw) v.findVIEwByID(R.ID.description); if (tt != null) { tt.setText(p.getID()); } if (tt1 != null) { tt1.setText(p.getcategory().getID()); } if (tt3 != null) { tt3.setText(p.getDescription()); } } return v; } }
这是我遇到问题的地方,试图声明listadapter
List <Item> tempList = new ArrayList <Item>(); ListVIEw yourListVIEw = (ListVIEw) findVIEwByID(androID.R.ID.List); // Here is the problem listadapter customAdapter = new listadapter(this, R.layout.List_item, List<tempList> //the error occurs right here); yourListVIEw .setAdapter(customAdapter);
解决方法:
更改
listadapter customAdapter = new listadapter(this, R.layout.List_item,List<tempList>)
至
listadapter customAdapter = new listadapter(this, R.layout.List_item, tempList); //...........
删除列表只需添加tempList
总结以上是内存溢出为你收集整理的如何将ArrayAdapter设置为Listview – Android全部内容,希望文章能够帮你解决如何将ArrayAdapter设置为Listview – Android所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)