[英]set- and getListAdapter error
我不知道為什么它顯示錯誤。 有人可以幫我嗎。
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();
}
}
您的活動需要擴展ListActivity
而不是Activity
。
Activity
類中沒有可用的setListAdapter / getListAdapter方法。 如果您擴展ListActivity
則它們可用。
閱讀這個職位上如何使用ListActivity。
使用ListActivity代替Activity作為基類
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.