我創建了一個打開對話框的佈局,進入對話框後,用戶選擇確定/取消。我想刷新列表視圖再次查詢數據如何在關閉對話框後刷新listView到?
這裏是我的佈局,將打開對話框:
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent myIntent = new Intent(SchoolActivity.this, InsertSchool.class);
update();
startActivity(myIntent);
updateList();
}
});
update();
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);
點擊該按鈕後,我想刷新列表視圖。這裏是對話框(我認爲刷新將在ok &取消按鈕上完成)。
ib.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent=new Intent(InsertSchool.this, SchoolActivity.class);
startActivity(intent);
}
});
update();
mySQLiteAdapter = new Database(this);
mySQLiteAdapter.openToWrite();
cursor = mySQLiteAdapter.queueSchoolAll();
ib1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String data1 = ie1.getText().toString();
String data2 = ie2.getText().toString();
mySQLiteAdapter.insertSchool(data1, data2);
updateList();
Toast.makeText(getApplicationContext(), "Saved",
Toast.LENGTH_SHORT).show();
Intent myIntent = new Intent(InsertSchool.this, SchoolActivity.class);
update();
startActivity(myIntent);
mySQLiteAdapter.close();
}
}
});
使用拉刷新庫therefreshData()方法.. https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&sqi=2&ved=0CCUQFjAA&url=https%3A%2F%2Fgithub.com%2Fchrisbanes%2FAndroid-PullToRefresh&ei=jk0MU7ryE4mRrAelyoCIDA&usg= AFQjCNFfDp36h1omRJIIVOtNBUQaFjigYw&bvm = bv.61725948,d.bmk&cad = rja – rajshree
我會試試看...感謝您的信息 – CJanon
請提供'update()'和'updateList()' –