0

How can I get touch event of different view in single touch as you can see in below image.

I had try with

 private void showAlert() {
    dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.temp_view);
    Button btnOne = (Button) dialog.findViewById(R.id.btnOne);
    Button btnTwo = (Button) dialog.findViewById(R.id.btnTwo);
    Button btnThree = (Button) dialog.findViewById(R.id.btnThree);
    btnTwo.setFocusableInTouchMode(true);
    btnTwo.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    Log.e("Down", ">>>>>>>>>>>>>button Two Down <<<<<<<<<<<<<<<");
                    break;
                case MotionEvent.ACTION_UP:
                    Log.e("Down", ">>>>>>>>>>>>>button Two UP <<<<<<<<<<<<<<<");
                    break;
            }
            return false;
        }
    });
    btnThree.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    Log.e("Down", ">>>>>>>>>>>>>button 3 Down <<<<<<<<<<<<<<<");
                    break;
                case MotionEvent.ACTION_UP:
                    Log.e("Down", ">>>>>>>>>>>>>button 3 UP <<<<<<<<<<<<<<<");
                    break;
            }
            return false;
        }
    });

    btnOne.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    Log.e("Down", ">>>>>>>>>>>>>button One Down <<<<<<<<<<<<<<<");
                    break;
                case MotionEvent.ACTION_UP:
                    Log.e("Down", ">>>>>>>>>>>>>button One UP <<<<<<<<<<<<<<<");
                    break;
            }
            return false;
        }
    });

    btnOne.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(TempTwitterTimelineActivity.this, "One", Toast.LENGTH_SHORT).show();
        }
    });
    View v = dialog.getCurrentFocus();
    if (v != null)
        switch (v.getId()) {
            case R.id.btnOne:
                Toast.makeText(TempTwitterTimelineActivity.this, "One", Toast.LENGTH_SHORT).show();
                break;
            case R.id.btnTwo:
                Toast.makeText(TempTwitterTimelineActivity.this, "Two", Toast.LENGTH_SHORT).show();
                break;
            case R.id.btnThree:
                Toast.makeText(TempTwitterTimelineActivity.this, "Three", Toast.LENGTH_SHORT).show();
                break;


        }
    dialog.show();
}

but it's only work when I re-touch other button.

Here you can see three different view event is fire in single touch, you can also check it in instagram search screen

I have an activity with button, opening a Custom Dialog on button touch event, in Custom Dialog I have three button Like, Share and View I would like to call function associate with button i.e View profile but other second touch, as when MotionEvent.ACTION_UP: is fire I dismiss dialog.

Here is Open Dialog code

txtTemp.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_UP:
                    if (dialog != null) {
                        if (dialog.isShowing()) {
                            dialog.dismiss();
                        }
                    }
                    break;
            }
            return false;
        }
    });

for get clear idea here is second image where I enable show touches from developer option and take screenshots.

Single Touch Multiple action fire without up fingure

Hitesh Dhamshaniya
  • 2,088
  • 2
  • 16
  • 23
  • Please explain what the problem is a little bit more. Reading your question, I don't know what you are trying to solve. – CaptJak Apr 06 '16 at 13:04
  • I have added more information and code in Question, I would like to implement functionality like in Instagram search screen has, when one long touch in search result at that time View is open that type of view I would like to make. – Hitesh Dhamshaniya Apr 06 '16 at 13:18
  • I still don't understand what you want to do. Do you want to call a method when one of the three buttons are touched? – CaptJak Apr 06 '16 at 13:21
  • there are there different method Like, Share and View need to call, without fingure up, i.e user drag fingure on like than like method should call, and from dragging his fingure and reach on share than share method should call, if you can check instagram android app, you get clear idea as my English is poor. – Hitesh Dhamshaniya Apr 06 '16 at 13:27
  • I think I get it. If the person presses "Like" and lifts his finger, you want the method for "Like" to fire. But if he drags his finger away, you don't want it to. Right? – CaptJak Apr 06 '16 at 13:34
  • Just use `OnClickListener(View)`, or set the `android:onClick` tag in the xml for your button. – CaptJak Apr 06 '16 at 14:15
  • no, that will not help, if the person press 'like' and drags his finger and reach at share button that share method should be call, without up his fingure. – Hitesh Dhamshaniya Apr 07 '16 at 04:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/108466/discussion-between-hitesh-androiduser3797630-and-captjak). – Hitesh Dhamshaniya Apr 07 '16 at 05:10

1 Answers1

0

I got one cool library in which developer make peekAndPop View, that resolve my problem.

Below is URL.

https://android-arsenal.com/details/1/3359

Thanks Vincent Te Tau

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Hitesh Dhamshaniya
  • 2,088
  • 2
  • 16
  • 23
  • Can you explain how to use this library with RecyclerView with Grid Layout, there is no documentation or sample provided. I want to implement a feature akin to instagram's peek&pop. – Harsh Vardhan May 25 '16 at 13:31
  • 1
    It's very simple , I think you create RecyclerView.Adater on adapter constructor you need to call peekandpopview – Hitesh Dhamshaniya May 26 '16 at 12:00