
Here是AndroID文档中的一个很好的教程,其源代码解释了GestureListvIEw.但我找不到如何在onGesturePerformed(GestureOverlayVIEw覆盖,手势手势)方法中获取列表项位置?
请查看代码中的注释?标记以理解我的查询.谢谢.
public class GesturesListActivity extends ListActivity implements OnGesturePerformedListener {private Gesturelibrary mlibrary;@OverrIDepublic 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(); } } }}}
解决方法:
我们可以覆盖
protected voID onListItemClick(ListVIEw l,VIEw v,int position,long ID)
这样就可以获得您单击的列表项的视图
总结以上是内存溢出为你收集整理的android – 如何在onGesturePerformed方法中获取列表项的位置?全部内容,希望文章能够帮你解决android – 如何在onGesturePerformed方法中获取列表项的位置?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)