0

I am having problem on back button of hardware. In my main Activity, I have one List view(say 1). When I click on item of this List view(1), one Alert Dialog appears, in this alert dialog, there is one List view(say 2). Data of this List view(2) are being repeated when I press back button of hardware. I have also put cancel image on this alert dialog to dismiss, when I press this cancel image, data are not being repeated. I tried different methods onResume(), onPause(), onDestroy(), onRestart() to clear the array for List view(2), but nothing works. Here is my code...

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;

// List view data are inserted with this function call private void showFriendList() { // TODO Auto-generated method stub 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();

            }
        });


        }

// I tried these methods, but nothing works...

@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;
}
Looking Forward
  • 3,579
  • 8
  • 45
  • 65

1 Answers1

0

I'm not sure but might be adding the following code to your onKeyDown method might help out :

return super.onKeyDown(keyCode, event);
arshu
  • 11,805
  • 3
  • 23
  • 21