/ / ANDROID - ListView ArrayAdapter (drukowanie określonego atrybutu) - android, listview, android-arrayadapter

ANDROID - ListView ArrayAdapter (specyficzny atrybut drukowania) - android, listview, android-arrayadapter

Używam listview w mojej aktywności listview z listAdapter tak jak poniżej:

setListAdapter(new ArrayAdapter<MyItem>(this,R.layout.catalog, R.id.label, items));

każdy element ma właściwość elementu ... w jaki sposób mogę go wydrukować?

Odpowiedzi:

2 dla odpowiedzi № 1

W swoim widoku listy dodaj TextView

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@+id/item_label"  />
</LinearLayout>

Ustaw wartość tego widoku tekstowego w metodzie zastępowania adaptera niestandardowego getView

@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;
}