2012-05-04 2 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 (ListView에 리터,보기 V, INT 위치, 긴 ID)이이 목록 항목의보기를 얻을 것이다 너무

당신을 클릭 했음

+0

하지만 항목을 클릭 할 때가 아니라 오히려 사용자가 미리 정의 된 방향으로 항목 위로 손가락을 밀 때 위치가 필요합니다. onListItemClick은 세부적인 연락처를 표시하는 것처럼 다른 기능을 갖습니다. 손가락을 왼쪽으로 움직이면 접촉이 제거됩니다. – Imon

관련 문제