Need to handle click event on drawableTop
of TextView
, written following code,
tvSocialMedia.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP) {
if(event.getRawX() <= tvSocialMedia.getTotalPaddingTop()) {
// your action for drawable click event
tvEmail.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.email,0, 0);
tvPhone.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.phone,0, 0);
tvAddress.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.address,0, 0);
tvSocialMedia.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.social_media_select,0, 0);
usage.setText(getResources().getString(R.string.social_media));
return true;
}
}
return true;
}
});
But code inside if(event.getAction() == MotionEvent.ACTION_UP)
is not getting executed. Correct me if I have written wrong condition in if statement.