2012-10-01 15 views
0

有人可以建議如何檢測列表視圖是否超出範圍?我在列表視圖中只有一個項目。我需要檢測用戶向上或向下滑動並且相應的列表視圖向上或向下顯示,並在其上方或下方顯示空的空間。在這一刻,我應該更新我的列表視圖的適配器並在那裏傳遞新項目。檢測列表視圖是否超出範圍並傳入新項目

我試着用GestureListener實現它是這樣的:

class MyGestureListener extends SimpleOnGestureListener implements OnTouchListener 
     { 

     public boolean onDown(MotionEvent arg0) { 
      InteractionsAdapter adapter = new InteractionsAdapter(InteractionsActivityAlt.this, 
        R.layout.interactions_item, DashboardActivityAlt.messagesExport,DashboardActivityAlt.messagesExport.size()-2); 
      adapter.notifyDataSetChanged(); 
      Log.i("asd","sdas"); 
      return true; 
     } 
     public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, 
       float velocityY) { 
      if(Math.abs(e1.getY()-e2.getY()) > 250) 
       return false;    
      if(e1.getX() - e2.getX() > 120// && Math.abs(velocityX) > 200 
        ){ 

       //mSwipeDetected = Action.RL; 
       Log.d("one", "Coords: x=" + e1.getX() + ",y=" + e2.getY()); 
       //do something... 
      return true; 
      } 
      else if(e2.getX() - e1.getX() > 120// && Math.abs(velocityX) > 200 
        ){ 

      // mSwipeDetected = Action.LR; 
       Log.d("two", "Coords: x=" + e1.getX() + ",y=" + e2.getY()); 
       //do something... 
      return true; 
      } 
      return false; 
     } 
     public void onLongPress(MotionEvent arg0) { 
      AlertDialog.Builder builder = new AlertDialog.Builder(InteractionsActivityAlt.this); 
      builder.setMessage("Are you sure to choose timezone "+" ?") 
      .setCancelable(false) 
      .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 

       } 
      }) 
      .setNegativeButton("No", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 

        dialog.cancel(); 
       } 
      }); 
     AlertDialog alert = builder.create(); 
     alert.show(); 

     } 
     public boolean onScroll(MotionEvent e1, MotionEvent e2, float arg2, 
       float arg3) { 


      float pos = e2.getY() - e1.getY(); 
      if (pos < -170 & pos > -200) 
      { 


       mSwipeDetected = Action.BT; 

       try { 

        Log.i("gesturelistener", "Move down"); 
       } 

      catch (Exception e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 

      } 
      if (pos > 170 & pos < 200) 
      { 

       mSwipeDetected = Action.BT; 

       try { 

        Log.i("gesturelistener", "Move up"); 
       } 

      catch (Exception e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 

      } 

      return true; 
     } 
     public void onShowPress(MotionEvent arg0) { 
      // TODO Auto-generated method stub 

     } 
     public boolean onSingleTapUp(MotionEvent arg0) { 
      // TODO Auto-generated method stub 
      return false; 
     } 

     public boolean onTouchEvent(MotionEvent me) 
     { 

     return gestureScanner.onTouchEvent(me); 
     } 
     public boolean onTouch(View arg0, MotionEvent arg1) { 
      if (arg1.getAction()==MotionEvent.ACTION_UP) 
       arg0.setBackgroundColor(Color.WHITE); 
      return false; 
     } 
     } 

它檢測刷卡向上或向下的動作,但不是在列表視圖去出界,並顯示空的空間。

+0

不能使用滾動視圖?它認爲它執行相同的工作。 –

+0

也許,但我需要檢測當用戶滑動屏幕時,它是在列表視圖的底部,當空的空間上方或下方的列表視圖顯示... –

+1

我希望這會幫助http://stackoverflow.com/ q/2089552/1643325 –

回答

0

我解決了與方法我的問題:

@Override 
public boolean onSingleTapUp(MotionEvent e) { 
    return true; 
}