2012-03-09 4 views
0

私はアンドロイド開発から始まります。私はカレンダーの活動をしたいと思います。私はそれを持っている活動を持ってのような方法で、にonFling()のような方法を実装し、カレンダーの月を変更します。これは正常に動作します。Android:間違ったリスナーの動作ですか?

その後、私のカレンダーには複数のセルが1日に1つあります。この日のイベントを追加するために、各セルにonclickリスナーを追加しました。これを行うと、gestureListenerが機能しなくなり、セルのクリックイベントだけがキャプチャされますが、動作していないジェスチャーをスワイプします(onFling()メソッドは呼び出されません)。私に何ができる?

これは私のコードです:あなたはセルで作業しているときにGestureListenerを使用しているビューがフォーカスを失うているよう

public class Calendar extends Activity implements OnGestureListener{ ... 

//OnFling method that detects the swipe gesture 
@Override 
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) 
    { 
     try { 
      if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) 
       return false; 
      // right to left swipe 
      if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 
       Toast.makeText(getApplicationContext(), "Left Swipe", Toast.LENGTH_SHORT).show(); 
      } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 
       Toast.makeText(getApplicationContext(), "Right Swipe", Toast.LENGTH_SHORT).show(); 
      } 
      else if(e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 
       Toast.makeText(getApplicationContext(), "Swipe up", Toast.LENGTH_SHORT).show(); 
      } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 
       Toast.makeText(getApplicationContext(), "Swipe down", Toast.LENGTH_SHORT).show(); 
      } 
     } catch (Exception e) { 
     Toast.makeText(this, "exception", Toast.LENGTH_SHORT).show(); 
     } 

     return true; 
    } 

//This is the method attached to each cell for onclick event 
public void showDialog(View v){ 
    TextView dia = (TextView)v.findViewWithTag("dia");  
    Intent i = new Intent(this, DialogoCalendario.class); 
    i.putExtra("dia",(String) dia.getText()); 
    i.putExtra("mes", ((TextView) findViewById(R.id.tbMes)).getText().toString()); 
    startActivity(i); 
} 
+0

コードを表示し、次のリンクを参照してください。https://www.google.co.jp/search?q=detect+swipe+gestures+android&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en -US:official&client = firefox-a – Shruti

+0

コード – user1116714

答えて

0

が見えます。あなたがセルで終わったらcalendarCellView.clearFocus();で試してみてください。

+0

で私の投稿を更新しましたが、まだ問題は... – user1116714

関連する問題