i have a button on my project and the effect gone on touch event. i want that when someone touch that button it should change.but nothing working for me from the XML. here is my code below. java code.
btnOn.setOnTouchListener(new View.OnTouchListener() {
//@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mConnectedThread.write("A");
Toast.makeText(getBaseContext(), "LED ON NOW", Toast.LENGTH_SHORT).show();
return true;
}
if (event.getAction() == MotionEvent.ACTION_UP) {
mConnectedThread.write("C");
Toast.makeText(getBaseContext(), "LED SWITCHED OFF", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
and here is the XML code below.
<Button
android:id="@+id/buttonOn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LED ON/OFF"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="148dp"/>