I tried to develop a CustomList that extends ListActivity.
Right now I am searching for a possibility to add different images to each line.
Who can help me?
Greetings,
Marco
Using java Syntax Highlighting
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import android.app.ListActivity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.ListView;
- import android.widget.SimpleAdapter;
- public class CustomList extends ListActivity {
- List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- setContentView(R.layout.customlist);
- Intent i = new Intent();
- i.setClass(CustomList.this, SomeActivity1.class);
- addItem( list, "Fußball (525)", i );
- i = new Intent();
- i.setClass(CustomList.this, SomeActivity2.class);
- addItem( list, "Deutschland (28)", i );
- i = new Intent();
- i.setClass(CustomList.this, SomeActivity3.class);
- addItem( list, "1. Bundesliga (9)", i );
- SimpleAdapter notes = new SimpleAdapter(this, list,
- R.layout.customlist_item_two_line_row,
- new String[] { "title" }, new int[] { R.id.text1 });
- setListAdapter(notes);
- }
- public void addItem(List<Map<String,Object>> data, String name, Intent intent) {
- Map<String, Object> temp = new HashMap<String, Object>();
- temp.put("title", name);
- temp.put("intent", intent);
- data.add(temp);
- }
- @Override
- public void onListItemClick(ListView l, View v, int position, long id) {
- Map map = (Map) l.getItemAtPosition(position);
- Intent intent = (Intent) map.get("intent");
- startActivity(intent);
- }
- }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <ListView android:id="@+id/android:list"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent" />
- <TextView android:id="@+id/android:empty"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- />
- </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <ImageView android:id="@+id/iv"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/soccer" />
- <TextView android:id="@+id/text1"
- android:textSize="16px"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:text="Text..."
- android:paddingTop="13px"
- android:paddingLeft="3px" />
- </LinearLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


