我在硬件的后退按钮上遇到问题。在我的主要活动中,我有一个列表视图(比如 1)。当我单击此列表视图(1)的项目时,会出现一个警报对话框,在此警报对话框中,有一个列表视图(例如 2)。当我按下硬件的后退按钮时,此列表视图(2)的数据正在重复。我还在此警报对话框上放置了取消图像以关闭,当我按下此取消图像时,不会重复数据。我尝试了不同的方法 onResume()、onPause()、onDestroy()、onRestart() 来清除 List view(2) 的数组,但没有任何效果。这是我的代码...
case LIST_DIALOG :
LayoutInflater inflater2 = LayoutInflater.from(this);
View dialogview1 = inflater2.inflate(R.layout.listdialog, null);
AlertDialog.Builder dialogbuilder2 = new AlertDialog.Builder(this);
dialogbuilder2.setView(dialogview1);
dialogDetails = dialogbuilder2.create();
case LIST_DIALOG:
AlertDialog alertDialog1 = (AlertDialog) dialog;
// Cancel Alert Dialog
ImageView ivCancel = (ImageView) alertDialog1.findViewById(R.id.imgCancel);
ivCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dismissDialog(LIST_DIALOG);
arr2.clear();
}
});
// Friend List
showFriendList();
break;
// 使用此函数调用插入列表视图数据 private void showFriendList() { // TODO 自动生成的方法存根 Request.executeMyFriendsRequestAsync(friendSession, new GraphUserListCallback() {
@Override
public void onCompleted(List<GraphUser> users, Response response) {
// TODO Auto-generated method stub
// arr2 = new ArrayList<String>();
for(GraphUser user : users)
{
arr2.add(user.getName());
}
adapter2 = new ArrayAdapter<String>(getBaseContext(), R.layout.single_row, R.id.txt,arr2);
lvDialog.setAdapter(adapter2);
lvDialog.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
adapter2.notifyDataSetChanged();
itemCount = lvDialog.getCount();
Toast.makeText(getBaseContext(), "" + itemCount, 1000).show();
}
});
}
// 我尝试了这些方法,但没有任何效果...
@Override
public void onResume()
{
super.onResume();
ShowSavedFiles();
arr2.clear();
}
@Override
public void onPause()
{
super.onPause();
arr1.clear();
arr2.clear();
}
@Override
public void onBackPressed() {
//super.onBackPressed();
// finish your Activity
arr2.clear();
return;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
arr2.clear();
dismissDialog(LIST_DIALOG);
}
return false;
}