Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.app.ListActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.ArrayAdapter;
- import android.widget.ListView;
- import android.widget.Toast;
- public class MyListActivity extends ListActivity {
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- String[] values = new String[] { "Google", "Yahoo", "Facebook"};
- // Use your own layout
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
- R.layout.rowlayout, R.id.label, values);
- setListAdapter(adapter);
- }
- @Override
- protected void onListItemClick(ListView l, View v, int position, long id) {
- String item = (String) getListAdapter().getItem(position);
- Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
- }
- }
- /*
- row_layout.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" >
- <TextView
- android:id="@+id/label"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@+id/label"
- android:textSize="20px" >
- </TextView>
- </LinearLayout>
- */
Advertisement
Add Comment
Please, Sign In to add comment