2
這裏是我的代碼 - PadsGrid是一個ViewGroup - :爲什麼我的ViewGroup的孩子觸摸事件不起作用?
public class Emc_PadControllerActivity extends Activity implements OnTouchListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final PadsGrid pg = new PadsGrid(this, 8, 5, PadType.SMALL);
for (int i=0;i<pg.getChildCount();i++){
final PadController pc;
pc=(View) pg.getChildAt(i);
pc.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
pc.onTouch(arg0,arg1);
return true;
}});;
}
setContentView(pg);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
v.onTouchEvent(event);
return false;
}
}
在這方面,onTouch事件我的觀點is'nt打電話,爲什麼我摸不到,爲什麼?
好吧,但我想直接導管的的onTouchEvent的意見。 因爲這種方式更快,更容易處理多點觸控事件! – nonozor 2012-04-14 17:02:04
在這種情況下,你應該可以'pc.setOnTouchListener(pc.onTouch());'...我假設pc類有一個onTouch()方法。 – cstrutton 2012-04-14 17:06:02
當然可以,但是如何傳遞兩個參數:Event和View到onTocuh方法? – nonozor 2012-04-14 17:12:05