1. MainActivity.java
package com.example.belajaralert;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import android.widget.Toast;
public class MainActivity extends ListActivity {
String[] wisataTegal = { "Guci",
"Pantai Alam Indah",
"Waduk Cacaban",
"Pantai Purwahamba",
"Alun-Alun Slawi",
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setListAdapter(new ArrayAdapter<string>(this,android.R.layout.simple_list_item_1, wisataTegal));
}
public void onListItemClick(ListView parent, View v, int urutan, long id) {
Object detail = this.getListAdapter().getItem(urutan);
String tampil = detail.toString();
Toast.makeText(this, "Wisata Tegal : " + tampil, Toast.LENGTH_SHORT).show();
}
}
2. activity_main.xml
<linearlayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical" xmlns:
android="http://schemas.android.com/apk/res/android">
<listview
android:drawselectorontop="false"
android:id="@android:id/list"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</listview>
</linearlayout>
</string>
Next
« Prev Post
« Prev Post
Previous
Next Post »
Next Post »
Langganan:
Posting Komentar (Atom)
EmoticonEmoticon
Catatan: Hanya anggota dari blog ini yang dapat mengirim komentar.