I don't know why it shows an error. Can somebody help me.
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);
In the next Line it shows me an error, namely:
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")
In the next Line it shows me an error, namely: Multiple makers at this line - The method getArrayAdapter() is undefined for the type MainActivityT - The method qetlistAdapter() is undefined for the tvpe MainActivitvT
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();
}
}
Your activity need to extend ListActivity
instead of Activity
.
There is no method setListAdapter/getListAdapter available in Activity
class. They are available if you extend ListActivity
.
Read this post on how to use ListActivity.
使用ListActivity代替Activity作为基类
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.