Showing posts with label Custom ListView. Show all posts
Showing posts with label Custom ListView. Show all posts

Tuesday, December 13, 2011

Android ListView Simple Adapter(custom style) example

This is an example of a very simple list view with custom style/layout.
ListView itemListView = (ListView)findViewById(R.id.itemChoseList);
List docList = new ArrayList();
HashMap<String,String> temp = new HashMap<String,String>();
temp.put("docTitile1", "My Title");
temp.put("docTitile2", "Sub title");
docList.add(temp);
simpleAdapter = new SimpleAdapter(
this,
docList,
R.layout.doc_row_lite,
new String[] {"docTitile1","docTitile2"},
new int[] {R.id.doc_lite_title1, R.id.doc_lite_title2});
itemListView.setAdapter(simpleAdapter);

doc_row_lite.xml
<?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="wrap_content"
android:padding="2dip">

<TextView
android:id="@+id/doc_lite_title1"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="18dip"
android:gravity="center_vertical"
/>
<TextView
android:id="@+id/doc_lite_title2"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:textSize="13dip"
android:text="shamim"
android:textColor="#111133"
android:singleLine="true"/>
</LinearLayout>