使用ListView和Actionbar时遇到问题。我将它用于Actionbar:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.maths:
Toast.makeText(getApplicationContext(), "Du bist bereits bei Mathe :)", Toast.LENGTH_SHORT).show();
return true;
case R.id.physics:
Intent myIntent2 = new Intent(Home.this, ActivityPhysics.class);
startActivity(myIntent2);
default:
return super.onOptionsItemSelected(item);
}
}
它完美无缺。现在我说扩展名单。在list.java中我有:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter( new ArrayAdapter<String>(this, R.layout.single_item, Liste));
ListView Liste = getListView();
Liste.setTextFilterEnabled(true);
Liste.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), ((TextView) arg1).getText(), Toast.LENGTH_SHORT) .show();
}
});
}
当我评论(//,/ * * /)动作栏时,Listview可以正常工作。当我评论Listview时,Actionbar可以工作。两者都产生了一个nullpointerexception并且&#34; youapp意外停止&#34;。
有没有办法让两者兼得?或者我可能错过了什么? :(