Hallo Leute,
ich möchte gerne, wie man es kennt eine Liste machen wo jedes item eine ImageView sowie eine TextView nebeneinander haben.
Darum habe ich mir einen Adapter gebaut:
Code
public class ItemsList extends ListActivity
{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//final String[] countries = new String[] {
// "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra"};
MyCustomAdapter mAdapter = new MyCustomAdapter(getApplicationContext());
/*for (int i = 0; i < 10; i++) {
mAdapter.addItem("item");
}*/
//setListAdapter(mAdapter);
setListAdapter(mAdapter);
}
}
class MyCustomAdapter extends BaseAdapter {
LayoutInflater mInflater;
ArrayList mData;
//String[] countries;
public MyCustomAdapter(Context context)
{
//this.countries = countries;
//mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mInflater = LayoutInflater.from(context);
mData.add("hallo");
mData.add("hallo2");
mData.add("hallo3");
}
@Override
public int getCount() {
return mData.size();
}
/*public void addItem(final String item) {
mData.add(item);
notifyDataSetChanged();
}*/
@Override
public String getItem(int position) {
return mData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
System.out.println("getView " + position + " " + convertView);
ViewHolder holder = null;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item1, null);
holder = new ViewHolder();
holder.textView = (TextView)convertView.findViewById(R.id.text);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder)convertView.getTag();
}
holder.textView.setText((CharSequence) mData.get(position));
return convertView;
}
public static class ViewHolder {
public TextView textView;
}
}
Alles anzeigen
Ich habe jetzt schon ewig debuggt, aber ich finde meinen fehler nicht. Danke für eure Hilfe.
MfG maximilian