我可以编辑或删除单个项目而没有任何问题,但是当我在编辑项目后单击删除按钮时,该项目仍然显示在ListView上,即使它已从数据库中删除。
ListViewActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_requests);
requestsList = new ArrayList<HashMap<String, String>>();
new LoadAllRequests().execute();
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String request_id = ((TextView) view.findViewById(R.id.request_id)).getText().toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(),
ViewRequestActivity.class);
// sending rid to next activity
in.putExtra(TAG_ID, request_id);
// starting new activity and expecting some response back
startActivityForResult(in, 55);
}
});
}
答案 0 :(得分:1)
您应该使用invalidateViews
,而不是关闭并重新开启活动yourListView.invalidateViews();
答案 1 :(得分:1)
您必须再次将适配器签名到列表视图
答案 2 :(得分:0)
您也可以尝试刷新活动。我相信它是ListViewActivity.restart();