This tutorial shows how to add a button to your application and handle touch events.
app/res/layout/content_robot_layout.xml
goForward
and Text: FORWARD
.app/java/geist.re.mindroid/RobotControl
onCreate
method (it should be around line 123//Change the id here Button goForward = (Button) findViewById(R.id.button); goForward.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if(robot == null || robot.getConnectionState() != RobotService.CONN_STATE_CONNECTED){ return false; } switch(event.getAction()) { case MotionEvent.ACTION_DOWN: //Run motors return true; // if you want to handle the touch event case MotionEvent.ACTION_UP: //Stop motors return true; // if you want to handle the touch event } return false; } });
In case you just want to handle basic tap event, you can do it by adding onClick
method to your button.
Note, that releasing the button will not be handled.
onClick
field to your button definition and assign it a namne of a function you want to call in case of tap event.app/java/geist.re/mindroid/RobotControl
add the function of the same name as in the previoud step, that takes View v
as a parameter:public void goForward(View w){ //Do some col stuff in here }