我想刷新適配器以及我的列表。但我對將方法Myadapter.notifyDataSetChanged()和list.clear()放在哪裏有點困惑,以便他們能爲我工作...任何人都可以編輯我的代碼,並幫助我從它出來..這裏是我的代碼Myadapter.notifyDataSetChanged()拋出錯誤
@覆蓋
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
calendars = Uri.parse("content://com.android.calendar/events");
managedCursor = getContentResolver().query(calendars, null, null, null, null);
if(managedCursor.getCount()==0){
Toast.makeText(getBaseContext(), "There Is No Event To Show", Toast.LENGTH_SHORT).show();
Intent i=new Intent(DisplayEventActivity.this,EventCalendarActivity.class);
startActivity(i);
finish();
}else{
setContentView(R.layout.displayevent);
id=getIntent().getExtras().getLong("ID");
event_ListView=(ListView)findViewById(R.id.eventList);
event_ListView.setOnItemClickListener(this);
}
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
model.getEventTitleList().clear();
myadapter.notifyDataSetChanged();
event_ListView.setAdapter(myadapter);
if(id==9){
model=new MyEventModel(managedCursor);
myadapter=new MyListAdapter(getApplicationContext(), model.getEventTitleList());
event_ListView.setAdapter(myadapter);
}else if(id==10){
model=new MyEventModel(managedCursor);
myadapter=new MyListAdapter(getApplicationContext(), model.getEventTitleList());
event_ListView.setAdapter(myadapter);
}
}
public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
event_Id=model.getEventId();
System.out.println("Event id from disp="+event_Id);
Intent i=new Intent(DisplayEventActivity.this,UpdateEvent.class);
i.putExtra("EventId", event_Id);
startActivity(i);
}
}
正確。你可以請更改代碼嗎? – 2012-08-03 08:09:43