6

I call this function in my activity :

@Override
public boolean dispatchTouchEvent(MotionEvent touchEvent)

That allows me to process action before any components get focused or even deny the focus to these elements.

PROBLEM : I was wondering how I could know what component (View) has been touched in this function, then I could choose if I want to consumme the event or not.

UGLY SOLUTION : I'm currently having an ugly solution which is : I know the position of the component that is allowed to get the event, and I do a plenty of condition to approximately decide if the user clicked on this component.

Thanks.

4

2 回答 2

0

您可能想使用OnTouchListener

private OnTouchListener mOnTouchListener= new OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {

          switch(v.getId()){

              case R.id.id1): 
              // Do stuff
              break;

              case R.id.id2: 
              // Do stuff
              break;
              }    

        return false/true;
    }
};
于 2012-07-12T10:24:01.457 回答
-1

view.getid==R.id.//布局中的id//条件可以检查需要的视图被点击

于 2012-07-23T11:49:06.263 回答