2012-01-02 9 views
0

から活動中の関数は、私は、カスタムのキャンバスとの主な活性を有しています。 SimpleOnGestureListener(onSingleTapConfirmedなど)のメソッドからqwerty()を呼び出したいコールSimpleOnGestureListener

これは可能ですか?そうでない場合は、そうする別の方法がありますか? おかげ

.... EDIT .....(詳細)

GestureDetectorは、次の2つのオプションを持って、私のCustomCanvas内のオブジェクト

public class CustomCanvas extends View { 

    GestureDetector gd; 
    ... 

    public CustomCanvas(final Context context) { 
     super(context); 

     gd = new GestureDetector(getContext(), new SimpleOnGestureListener() { 
      .... 
      // I also use getScrollX() and getScrollY() in some of the methods here 
     }); 
    } 

    .... 

    @Override 
    public boolean onTouchEvent(MotionEvent ev) { 
     return gd.onTouchEvent(ev); 
    } 
} 
+0

私たちも 'GestureDetector'を見せてください。これは同じクラスですか? –

答えて

0

です。アクティビティにSimpleOnGestureListenerを実装し、それをCustomCanvasに設定​​するか、ActivityをCustomCanavasに渡して、CustomCanvasクラスのリスナーからqwerty()を呼び出すことができます。あなたActivityクラスで

UPDATE

public class CustomCanvas extends View { 

    GestureDetector gd; 
    YourActivity mYourActivity; 
    ... 

    public CustomCanvas(final Context context) { 
     super(context); 

     gd = new GestureDetector(getContext(), new SimpleOnGestureListener() {     
       public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){ 
        // this implementation makes no sense 
        if(mYourActivity != null){ 
        mYourActivity.qwerty(); 
        }  
       }  
     }); 
    } 

    public setActivity(YourActivity activity){ 
     mYourActivity = activity; 
    } 
} 

あなたはCustomCanvasに活動を渡す必要があります。

public class YourActivity { 

    public void onCreate(Bundle savedInstanceState) { 
     ... 
     CustomCanvas c = new CustomCanvas(this); 

     // pass the activity to the canvas 
     c.setActivity(this); 

     c.requestFocus(); 
     cll = (LinearLayout)findViewById(R.id.CLL); 
     cll.addView(c); 
    } 

    public void qwerty(String w) { 
     .... 
     TextView abc = (TextView)findViewById(R.id.TextViewabc); 
     abc.setText(w); 
     .... 
    } 
} 
+0

どうすればいいですか? >< – user1126234

+0

あなたはSimpleCheckerクラスを実装してSimpleOnGestureListenerをオーバーライドしますか? – Flo

+0

はい。私はonScroll、onFling、onDown、onSingleTapConfirmedメソッドをオーバーライドします。 – user1126234