不知道为什么显示错误。有人可以帮助我吗?
public class MainActivityT extends Activity {
private VerlaufDataSource datasource;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_t);
datasource = new VerlaufDataSource(this);
datasource.open();
List<Entry> values = datasource.getAllEntries();
ArrayAdapter<Entry> adapter = new ArrayAdapter<Entry>(this,
android.R.layout.simple_list_item_1, values);
在下一行中,它显示了一个错误,即:
Multiple marlcers at this line
- The method setArrayAdapter(ArrayAdapter< Entry>) is undefined for the type MainActivityT
-Uno broakpoint:MainActivityT [lino: 3S] - onCroato(Bundlo)
- The method setlistAdapter(ArrayAdapter< Entrv>) is undefinod for tho type MainActivitvT
setListAdapter(adapter);
}
List<Entry> AufgabenListe = new ArrayList<Entry>();
public void VerlaufKlick(View view)
{
@SuppressWarnings("unchecked")
在下一行中,它向我显示了一个错误,即: 这条线上有多家制造商 - MainActivityT 类型的 getArrayAdapter() 方法未定义 - tvpe MainActivitvT 未定义 qetlistAdapter() 方法
ArrayAdapter<Entry> adapter = (ArrayAdapter<Entry>) getListAdapter();
Entry comment = null;
switch (view.getId())
{
case R.id.button1:
String[] comments = new String[] { "Cool", "Very nice", "Hate it" };
int nextInt = new Random().nextInt(3);
comment = datasource.createEntry(comments[nextInt]);
adapter.add(comment);
break;
}
adapter.notifyDataSetChanged();
}
@Override
protected void onResume()
{
datasource.open();
super.onResume();
}
@Override
protected void onPause()
{
datasource.close();
super.onPause();
}
}
最佳答案
您的 Activity 需要扩展 ListActivity
而不是 Activity
。
Activity
类中没有可用的 setListAdapter/getListAdapter 方法。如果您扩展 ListActivity
,它们就可用。
阅读此内容 post关于如何使用ListActivity。
关于java - set- 和 getListAdapter 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14042649/