2012-05-04 6 views
4

Hereは、GestureListviewを説明しているソースコードを含むAndroidドキュメントの優れたチュートリアルです。しかし、私は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(リストビューリットル、ビューV、int型の位置、長いID)

を上書きすることができます

+0

しかし、アイテムがクリックされたときには必要ではなく、ユーザーが指を所定の方向にスライドさせたときにその位置が必要です。 onListItemClickは、詳細な連絡先を表示するような異なる機能を持ちます。そして指を左にスライドさせると、接触が取り除かれます。 – Imon

関連する問題