1. Buat projek baru dan beri nama 'ListView'
2. Buat kode program pada 'activity_main.xml'
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"
tools:context=".MainActivity"
/>
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
></ListView>
</LinearLayout>
3. Selanjutnya buat kode program pada 'MainActivity.java'
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.app.ListActivity;
public class MainActivity extends
ListActivity {
String[] hewan = new String[] {"Anjing", "Kucing", "Kuda", "Beruang", "Tikus"};
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
this.setListAdapter(new
ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, hewan));
//setContentView(R.layout.activity_main);
}
protected void
onListItemClick(ListView l, View v, int position, long id) {
Toast.makeText(this, "Membuka
Form " + hewan[position], Toast.LENGTH_LONG).show();
}
}