Hi i want to create 2 Button and i want to multitouch ??
i tryed to do but no example in internet..
So if you got one can you share or can you give me opinion ?? my code is this but not support multitouch
package multi.touch;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.AbsoluteLayout.LayoutParams;
import android.widget.Button;
import android.widget.TextView;
public class baslat extends Activity implements OnTouchListener {
TextView yazi;
TextView bir,iki;
Button buton1,buton2;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
yazi=(TextView)findViewById(R.id.textView1);
bir=(TextView)findViewById(R.id.textView2);
iki=(TextView)findViewById(R.id.textView3);
buton1=(Button)findViewById(R.id.button1);
buton2=(Button)findViewById(R.id.button2);
buton2.setOnTouchListener(this);
buton1.setOnTouchListener(this);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
yazi.setText(String.valueOf(event.getPointerCount()+"\n\n"));
bir.setText(String.valueOf("Birinci "
+ (int)event.getX(0)+"\n\n"+(int)event.getY(0)));
iki.setText(String.valueOf("Ikinci"+
(int)event.getX(1)+"\n\n"+(int)event.getY(1)));
//buton2.setLayoutParams(new
LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,
(int)event.getX(0),
(int)event.getY(0))); return
super.onTouchEvent(event);
} @Override public boolean onTouch(View v, MotionEvent event) {
Button fds=(Button)v;
return false; }
}
Did you check this link -
How to use Multi-touch in Android 2
http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2/1747
How to code for multitouch
In the Android UI framework, all touch events belong to the View where the touch originated. So if you touch your Button, all touch events are processed through that Button until you lift your finger up; this includes other touch pointers for multi-touch. In my experience the only way to achieve multi-touch across separate View objects (your 2 Buttons), is to capture all touch events in one View that covers the whole screen, and delegate the touch events yourself. It's a bit of work, but it can be done.
An example might be to include an ImageView that fills the screen but has no Drawable source (or it's completely transparent). Put this on top of your other elements (perhaps with a FrameLayout), and in the onTouchEvent() method of the ImageView, analyze the touch coordinates, and pass the touch event down to the correct button. This gets rather complicated with multiple touch pointers, but as far as I know, it's the only way to pass touch events to separate View objects.
I was a little bored with this subject and i made an handler class for leading with multitouch buttons. Feel free to use and/or update that.
Old question but I was running my head in the wall with this problem until I finally came across just setting
on the layout view that contains the button views, which allows for multiple buttons to be pressed, which I found digging in the ApiDemos that are available in the sdk demos download