在我的對話框中修改,只有刪除工作正常,刷新良好...我的添加對話框和編輯對話框工作正常,但不刷新list-view
。我怎樣才能刷新這個?不能刷新listView,出了什麼問題?
下面是我的代碼片段。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.school_screen);
listContent = (ListView)findViewById(R.id.listView1);
mySQLiteAdapter = new Database(this);
mySQLiteAdapter.openToWrite();
cursor = mySQLiteAdapter.queueSchoolAll();
// Locate the button in activity_main.xml
button = (Button) findViewById(R.id.add_school_button);
// Capture button clicks
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
updateList();
Intent myIntent = new Intent(SchoolActivity.this, InsertSchool.class);
startActivity(myIntent);
}
});
cursor.requery();
String[] from = new String[]{Database.KEY_ID2, Database.KSCHOOL, Database.KSCHOOLCODE};
int[] to = new int[]{R.id.rid, R.id.rt1, R.id.rt2};
cursorAdapter =
new SimpleCursorAdapter(this, R.layout.row_school, cursor, from, to);
listContent.setAdapter(cursorAdapter);
listContent.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Cursor cursor = (Cursor) arg0.getItemAtPosition(arg2);
final int item_id = cursor.getInt(cursor.getColumnIndex(Database.KEY_ID2));
sdid.sdid(item_id);
Intent intent=new Intent(SchoolActivity.this,DetailsSchool.class);
startActivity(intent);
}
});
cursor.requery();
listContent.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Cursor cursor = (Cursor) arg0.getItemAtPosition(arg2);
final int item_id = cursor.getInt(cursor.getColumnIndex(Database.KEY_ID2));
AlertDialog.Builder myDialog = new AlertDialog.Builder(SchoolActivity.this);
myDialog.setTitle("Modify");
myDialog.setMessage("Do you want to edit or delete?");
myDialog.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
mySQLiteAdapter.delete_byID2(item_id);
updateList();
Intent intent=new Intent(SchoolActivity.this,SchoolActivity.class);
startActivity(intent);
}
});
myDialog.setNegativeButton("Edit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
updateSchool.id(item_id);
updateList();
Intent intent=new Intent(SchoolActivity.this, UpdateSchool.class);
startActivity(intent);
}
});
myDialog.show();
}
});
cursor.requery();
}
private void updateList(){
cursor.requery();
}
}
任何幫助表示讚賞
使用notifyDatasetChanged()刷新列表視圖。 – InnocentKiller