0
我已經創建了這個小程序來向用戶顯示屏幕上的手指,但問題是來自其他手指的X,Y值沒有被修改。我究竟做錯了什麼?Android觸摸屏監聽器問題
謝謝!
public class TestandoActivity extends Activity implements OnTouchListener {
/** Called when the activity is first created. */
private TextView txtV;
private TextView txtV2;
private int nf = 0;
private Map<Integer, String> info;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
info = new HashMap<Integer, String>();
setContentView(R.layout.main);
this.txtV = (TextView)this.findViewById(R.id.textview);
this.txtV2 = (TextView)this.findViewById(R.id.textview2);
this.txtV.setOnTouchListener(this);
}
public boolean onTouch(View v, MotionEvent event) {
int actionCode = event.getAction() & MotionEvent.ACTION_MASK;
int pid = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
info.put(pid, pid + ": X=" + event.getX() + " Y=" + event.getY() + " pressure=" + event.getPressure() + " size=" + event.getSize());
if (actionCode == MotionEvent.ACTION_POINTER_UP || actionCode == MotionEvent.ACTION_UP)
info.remove(pid);
String total = "";
for (Map.Entry<Integer, String> e : this.info.entrySet()) {
total += e.getValue() + "\n";
}
this.txtV2.setText(total);
return true;
}
}