Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 1.85 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. android-actionbar in a ListActivity
  2. public class DisciplinesController extends ListActivity {
  3.  
  4. private DisciplinesModel dbHelper;
  5. private Cursor cursor;
  6.  
  7. @Override
  8. public void onCreate(Bundle savedInstanceState) {
  9.     super.onCreate(savedInstanceState);
  10.     setContentView(R.layout.list_action);
  11.  
  12.     ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
  13.  
  14.     dbHelper = new DisciplinesModel(this);
  15.     dbHelper.open();
  16.     if (dbHelper.fetchDisciplineCount() == 0) {
  17.         dbHelper.fetch();
  18.     }
  19.     cursor = dbHelper.fetchAllDisciplines();
  20.     startManagingCursor(cursor);
  21.  
  22.     ListAdapter adapter = new SimpleCursorAdapter(this, R.id.list,
  23.             cursor, new String[] { "name" }, new int[] { R.id.discipline_name});
  24.     setListAdapter(adapter);
  25.     getListView().setTextFilterEnabled(true);
  26. }
  27. }
  28.        
  29. <?xml version="1.0" encoding="utf-8"?>
  30.  
  31. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  32. android:orientation="vertical" android:layout_width="fill_parent"
  33. android:layout_height="fill_parent">
  34.  
  35. <com.markupartist.android.widget.ActionBar
  36.     android:id="@+id/actionbar" style="@style/ActionBar" />
  37.  
  38. <LinearLayout android:id="@+id/list" android:layout_width="fill_parent"
  39.     android:layout_height="wrap_content">
  40.     <TextView android:id="@+id/discipline_name"
  41.         android:layout_width="fill_parent" android:layout_height="wrap_content"
  42.         android:textAppearance="?android:attr/textAppearanceLarge"
  43.         android:gravity="center_vertical" android:paddingLeft="6dip"
  44.         android:minHeight="?android:attr/listPreferredItemHeight" />
  45. </LinearLayout>
  46.  
  47. </LinearLayout>
  48.        
  49. Your content must have a ListView whose id attribute is 'android.R.id.list'
  50.        
  51. <ListView
  52.    android:id="@android:id/list"
  53.    ...
  54. />
  55.        
  56. <ListView
  57.    android:id="@android:id/list"
  58.    android:layout_width="fill_parent"
  59.    andrdoi:layout_height="wrap_content" />