I am stuck on a problem for a while now. I have 2 buttons on my app (button1 and button2) and I want to have it so when my finger moves over the first button it will say some thing like "In button 1" and then when I move my finger into button 2 it will say "In button 2" in the logcat.
I have it at the moment where I am able to click these buttons to get the text to appear but I don't want that. I want to be able to move my finger around without taking it off the screen to display the text. I would appreciate any help at all, thank you!
My code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_drag_drop);
buttonOne = (Button) findViewById(R.id.buttonOne);
buttonTwo = (Button) findViewById(R.id.buttonTwo);
buttonOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, " In button 1 ");
}
});
buttonTwo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, " In button 2 ");
}
});
Using the link I changed my code, but it didn't seem to work:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
rect1 = new Rect(buttonOne.getLeft(), buttonOne.getTop(),
buttonOne.getRight(), buttonOne.getBottom());
rect2= new Rect(buttonTwo.getLeft(), buttonTwo.getTop(),
buttonTwo.getRight(), buttonTwo.getBottom());
}
public boolean onTouch (View v, MotionEvent event){
if (event.getActionMasked() == (MotionEvent.ACTION_DOWN | MotionEvent.ACTION_MOVE)) {
if (rect1.contains((int) event.getX(), (int) event.getY())) {
Log.d(TAG, " in button1: ");
}
if (rect2.contains((int) event.getX(), (int) event.getY())) {
Log.d(TAG, " in button2: ");
}
}
return true;
}