我正在尝试刷新适配器以及我的列表。但是我对将方法 Myadapter.notifyDataSetChanged() 和 list.clear() 放置在哪里几乎没有什么困惑,这样它们就可以为我工作......任何人都可以编辑我的代码并帮助我摆脱它..这是我的代码
@覆盖
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);
}
}