0
我有硬件後退按鈕的問題。在我的主要活動中,我有一個List視圖(比如1)。當我點擊這個列表視圖(1)的項目時,出現一個警報對話框,在這個警報對話框中有一個列表視圖(比如2)。當按下硬件的按鈕時,此列表視圖(2)的數據正在重複。我也在這個提示對話框中放置了取消圖像,當我按下這個取消圖像時,數據沒有被重複。我嘗試了不同的方法onResume(),onPause(),onDestroy(),onRestart()清除列表視圖(2)的數組,但沒有任何工作。這裏是我的代碼...關閉後退按鈕上的自定義警報對話框在Android的硬件按下
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;
//插入此函數調用 私人無效showFriendList()列表視圖數據{// TODO自動生成方法存根 Request.executeMyFriendsRequestAsync(friendSession,新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;
}