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