Я создал реализацию ListView, а не ListActivity.
list_produk.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/lvListProduk"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.98"
tools:listitem="@layout/list_produk_row" >
</ListView>
<Button
android:id="@+id/btnListProdukBack"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/back_" />
</LinearLayout>
list_produk_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvProdukName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
ListProduk.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_produk);
String[] from = new String[] {"prd_name"};
int[] to = new int[] {R.id.tvProdukName};
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("prd_name", "BlackBerry");
fillMaps.add(map);
map = new HashMap<String, String>();
map.put("prd_name", "Android");
fillMaps.add(map);
map = new HashMap<String, String>();
map.put("prd_name", "iPhone");
fillMaps.add(map);
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.list_produk_row, from, to);
ListView listView = (ListView) findViewById(R.id.lvListProduk);
listView.setAdapter(adapter);
}
list_produk_row.xml, который содержит TextView, является макетом для элемента списка ListView.