1

When i show a android contact list on DialogFragment using startActivityForResult :

 contact.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                startActivityForResult(new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI), REQUEST_CODE_PICK_CONTACTS);
                return true;
            }
        });

);

when the list of contact appear i should click twice on contact or three time until the the list disappear instead of one click

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == REQUEST_CODE_PICK_CONTACTS && resultCode == getActivity().RESULT_OK) {
        uriContact = data.getData();
        contact.setText(name);
    }
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Mohamed Mellal
  • 49
  • 1
  • 12

1 Answers1

1

Instead of using on touch listener use on click listener. Your on touch is event is called thrice. (For touch down, touch up and cancel). If you want to use onTouch only, then put a if condition with event==MotionEvent.ACTION_DOWN or event==MotionEvent.ACTION_UP.

Bourbia Brahim
  • 14,459
  • 4
  • 39
  • 52
karandeep singh
  • 2,294
  • 1
  • 15
  • 22
  • in reality i want to add an event click on right drawable i don't find a solution – Mohamed Mellal Jan 02 '18 at 12:42
  • 1
    I think for that you can refer to this answer. [link] (https://stackoverflow.com/questions/13135447/setting-onclicklistner-for-the-drawable-right-of-an-edittext) @MohamedMellal – karandeep singh Jan 02 '18 at 12:51