Eclipse:getListView()。setListAdapter(mAdapter);

时间:2014-02-22 08:09:40

标签: android eclipse

Eclipse抱怨这行代码:

getListView().setListAdapter(mAdapter);

话说:

The method setListAdapter(ToDoListAdapter) is undefined for the type ListView

它表明:

  1. setListAdapter更改为setAdapter
  2. 或使用下一行代码:

    ListView((ListActivity)getListView())。setListAdapter(mAdapter);

  3. 有什么更好/更清楚的吗?

3 个答案:

答案 0 :(得分:1)

看起来您正在使用ListActivity。只需拨打该活动的电话setListAdapter()即可。

答案 1 :(得分:1)

您的活动必须延长ListActivitysetListAdapterListActivity的一种方法。所以你必须扩展ListAcitivity

所以改变

getListView().setListAdapter(mAdapter);

setListAdapter(mAdapter);

ListView没有setLiastAdapter

http://developer.android.com/reference/android/widget/ListView.html

http://developer.android.com/reference/android/app/ListActivity.html#setListAdapter(android.widget.ListAdapter)

public void setListAdapter (ListAdapter adapter)

Added in API level 1
Provide the cursor for the list view.

getListView

public ListView getListView ()

Added in API level 1
Get the activity's list view widget.

答案 2 :(得分:0)

要么是

ListActivity.setListAdapter

ListView.setAdapter()

ListActivity的setListAdapter是

的快捷方式
  

ListActivity.getListView.setAdapter()