2012-05-04 103 views
4

Here是Android文檔中的一個很好的教程,解釋了GestureListview的源代碼。但我找不到如何獲得onGesturePerformed(GestureOverlayView覆蓋,手勢手勢)方法中的列表項目位置?如何獲取onGesturePerformed方法中列表項的位置?

請參閱代碼中的評論?標記以瞭解我的查詢。謝謝。

public class GesturesListActivity extends ListActivity implements OnGesturePerformedListener { 
private GestureLibrary mLibrary; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    // Populate the activity with the names of our contacts 
    Cursor query = managedQuery(Contacts.People.CONTENT_URI, 
      new String[] { Contacts.People._ID, Contacts.People.DISPLAY_NAME }, 
      null, null, Contacts.People.DEFAULT_SORT_ORDER); 

    ListAdapter adapter = new SimpleCursorAdapter(this, 
      android.R.layout.simple_list_item_1, query, 
      new String[] { Contacts.People.DISPLAY_NAME }, 
      new int[] { android.R.id.text1 }); 

    setListAdapter(adapter); 

    mLibrary = GestureLibraries.fromRawResource(this, R.raw.actions); 
    if (!mLibrary.load()) { 
     finish(); 
    } 

    GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures); 
    gestures.addOnGesturePerformedListener(this); 
} 

public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { 
    ArrayList<Prediction> predictions = mLibrary.recognize(gesture); 
    if (predictions.size() > 0) { 
     if (predictions.get(0).score > 1.0) { 
      String action = predictions.get(0).name; 
      if ("action_add".equals(action)) { 
       Toast.makeText(this, "Adding a contact", Toast.LENGTH_SHORT).show();     
      } else if ("action_delete".equals(action)) { 
       Toast.makeText(this, "Removing a contact", Toast.LENGTH_SHORT).show(); 




       //How to get the specific position in the list to remove the contact on which the gesture event took place? 




      } else if ("action_refresh".equals(action)) { 
       Toast.makeText(this, "Reloading contacts", Toast.LENGTH_SHORT).show(); 
      } 
     } 
    } 
} 

}

回答

1

我們可以覆蓋 保護無效onListItemClick(ListView的L,視圖V,INT位置,長ID)

所以,這將獲取列表項的觀點,即你已點擊

+0

但我不需要它時,單擊項目,而是我需要的位置,當用戶在預定義的方向上滑動他的手指在項目上。 onListItemClick將具有不同的功能 - 就像它將顯示詳細的聯繫人一樣。向左滑動手指將移除接觸。 – Imon

相關問題