我在listview活动中使用listview和listAdapter,如下所示:
setListAdapter(new ArrayAdapter<MyItem>(this,R.layout.catalog, R.id.label, items));
每个项目都有项目属性......我怎么能打印出来?
答案 0 :(得分:2)
在列表视图布局中添加TextView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@+id/item_label" />
</LinearLayout>
在自定义适配器覆盖方法getView
中设置此textview的值@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.catalog, null);
}
MyItem m = items.get(position);
TextView itemLabel = (TextView) v.findViewById(R.id.item_label);
itemLabel.setText(m.getItemLabel());
return v;
}