Android List with Image - How to implement?

List_layout. Xml LinearLayout xmlns:android="schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> list = new ArrayList(); for ( loop through your data ) { list. Add(new ListRow("text", R.drawable.

Image)); } YourAdapter adapter = new YourAdapter(this, list); lv. SetAdapter(adapter) The classes class ListRow { private String text; private int resource; public ListRow(String text, int resource) { super(); this. Text = text; this.

Resource = resource; } public int getText() { return text; } public int getResource() { return resource; } } class YourAdapter extends BaseAdapter implements OnClickListener { private Context context; private List theList; public YourAdapter (Context context, List theList) { this. Context = context; this. TheList = theList; } public View getView(int position, View convertView, ViewGroup viewGroup) { ListRow row = theList.

Get(position); if (convertView == null) { LayoutInflater inflater = (LayoutInflater) context. GetSystemService(Context. LAYOUT_INFLATER_SERVICE); convertView = inflater.

Inflate(R.layout. Row_layout, null); } TextView tv = (TextView) convertView. FindViewById(R.id.

Row_text); tv. SetText(row.getText()); ImageView iv = (ImageView) convertView. FindViewById(R.id.

Row_image); iv. SetBackgroundResource(row.getResource()); return convertView; } @Override public void onClick(DialogInterface dialog, int which) { } }.

List_layout. Xml row_layout. Xml In onCreate() setContentView(R.layout.

List_layout); ListView lv = (ListView) findViewById(R.id. List); List list = new ArrayList(); for ( loop through your data ) { list. Add(new ListRow("text", R.drawable.

Image)); } YourAdapter adapter = new YourAdapter(this, list); lv. SetAdapter(adapter); The classes class ListRow { private String text; private int resource; public ListRow(String text, int resource) { super(); this. Text = text; this.

Resource = resource; } public int getText() { return text; } public int getResource() { return resource; } } class YourAdapter extends BaseAdapter implements OnClickListener { private Context context; private List theList; public YourAdapter (Context context, List theList) { this. Context = context; this. TheList = theList; } public View getView(int position, View convertView, ViewGroup viewGroup) { ListRow row = theList.

Get(position); if (convertView == null) { LayoutInflater inflater = (LayoutInflater) context. GetSystemService(Context. LAYOUT_INFLATER_SERVICE); convertView = inflater.

Inflate(R.layout. Row_layout, null); } TextView tv = (TextView) convertView. FindViewById(R.id.

Row_text); tv. SetText(row.getText()); ImageView iv = (ImageView) convertView. FindViewById(R.id.

Row_image); iv. SetBackgroundResource(row.getResource()); return convertView; } @Override public void onClick(DialogInterface dialog, int which) { } }.

See the full discussion about images in listview Source Code is available here : open-pim.com/tmp/LazyList.zip.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions