android-actionbar в ListActivity

1


Я пытаюсь создать плагин android-actionbar, который работает в моем ListActivity,

Здесь мой класс:

public class DisciplinesController extends ListActivity {

private DisciplinesModel dbHelper;
private Cursor cursor;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_action);

    ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);

    dbHelper = new DisciplinesModel(this);
    dbHelper.open();
    if (dbHelper.fetchDisciplineCount() == 0) {
        dbHelper.fetch();
    }
    cursor = dbHelper.fetchAllDisciplines();
    startManagingCursor(cursor);

    ListAdapter adapter = new SimpleCursorAdapter(this, R.id.list, 
            cursor, new String[] { "name" }, new int[] { R.id.discipline_name});
    setListAdapter(adapter);
    getListView().setTextFilterEnabled(true);
}
}

и мой XML-макет:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<com.markupartist.android.widget.ActionBar
    android:id="@+id/actionbar" style="@style/ActionBar" />

<LinearLayout android:id="@+id/list" android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView android:id="@+id/discipline_name"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:gravity="center_vertical" android:paddingLeft="6dip"
        android:minHeight="?android:attr/listPreferredItemHeight" />
</LinearLayout>

</LinearLayout>

У меня всегда есть это исключение:

Your content must have a ListView whose id attribute is 'android.R.id.list'

Есть ли у вас идея?

Спасибо!

Теги:

1 ответ

3
Лучший ответ

В вашем XML-макете вы должны включить элемент ListView с идентификатором @android: id/list.

<ListView
   android:id="@android:id/list"
   ...
/>

В принципе, вам нужно вырвать раздел LinearLayout в новый файл (например, list_item.xml). Замените это списком в list_action.xml

<ListView
   android:id="@android:id/list"
   android:layout_width="fill_parent"
   andrdoi:layout_height="wrap_content" />

Затем смените R.id.list в свой конструктор SimpleCursorAdapter на R.layout.list_item.

  • 0
    Как это работает с моим курсором тогда?
  • 0
    Извините, отредактировал это, чтобы добавить больше деталей, должен ответить на этот вопрос сейчас.
Показать ещё 2 комментария

Ещё вопросы

Сообщество Overcoder
Наверх
Меню