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.
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.