ashish2py

Android Custom listview

Dec 19th, 2011
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. import android.app.ListActivity;
  2. import android.os.Bundle;
  3. import android.view.View;
  4. import android.widget.ArrayAdapter;
  5. import android.widget.ListView;
  6. import android.widget.Toast;
  7.  
  8. public class MyListActivity extends ListActivity {
  9.     public void onCreate(Bundle icicle) {
  10.         super.onCreate(icicle);
  11.         String[] values = new String[] { "Google", "Yahoo", "Facebook"};
  12.  
  13.         // Use your own layout
  14.         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
  15.                 R.layout.rowlayout, R.id.label, values);
  16.         setListAdapter(adapter);
  17.     }
  18.  
  19.     @Override
  20.     protected void onListItemClick(ListView l, View v, int position, long id) {
  21.         String item = (String) getListAdapter().getItem(position);
  22.         Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
  23.     }
  24. }
  25.  
  26.  
  27. /*
  28.  
  29. row_layout.xml
  30.  
  31. <?xml version="1.0" encoding="utf-8"?>
  32. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  33.     android:layout_width="wrap_content"
  34.     android:layout_height="wrap_content" >
  35.  
  36.     <TextView
  37.         android:id="@+id/label"
  38.         android:layout_width="wrap_content"
  39.         android:layout_height="wrap_content"
  40.         android:text="@+id/label"
  41.         android:textSize="20px" >
  42.     </TextView>
  43.  
  44. </LinearLayout>
  45. */
Advertisement
Add Comment
Please, Sign In to add comment