标签:android listview gesture simplecursoradapter
我正在编写一个简单的Android应用程序,其中包含一个填充了SimpleCursorAdapter的列表.
private void populateList() {
c = this.cDAO.fetchAllContacts();
startManagingCursor(c);
String[] from = new String[]{ContactsDAO.KEY_NOME};
int[] to = new int[]{R.id.nome1};
SimpleCursorAdapter notes =
new MyListAdapter(this, R.layout.list_row, c, from, to, activitySwipeDetector);
setListAdapter(notes);
}
列表和list_row的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listaBottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#B5E61D"
>
<ListView android:id="@+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#B5E61D"
android:divider="#80FFFF"
android:dividerHeight=".5dp"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/nome1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:textColor="#5289DC"
/>
此外,我在listview上设置了一个OnTouchListener来监听正常工作的滑动和点击事件,除了它不会侦听列表中任何项目中发生的事件.做一些研究我发现我需要扩展SimpleCursorAdapter来为所有项添加监听器.这是我的扩展课程:
public class MyListAdapter extends SimpleCursorAdapter {
ActivitySwipeDetector asd;
public MyListAdapter(Context context, int layout, Cursor c, String[] from, int[] to, ActivitySwipeDetector asd) {
super(context, layout, c, from, to);
this.asd = asd;
}
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView row = (TextView)view.findViewById(R.id.nome1);
row.setOnTouchListener(asd);
return view;
}
}
这不起作用.有没有人知道如何使它工作?
编辑:只是为了澄清,我想要的是识别列表项目上的手势(向左滑动,向右滑动,单击).到目前为止,如果我在列表的空白部分(在项目下)执行手势,则侦听器会捕获事件,但如果我在某个项目上执行此操作,则无法识别滑动.
解决方法:
我在问题中发布的代码工作正常.问题出在我的触摸侦听器中,它没有执行手势事件请求的操作.
标签:android,listview,gesture,simplecursoradapter 来源: https://codeday.me/bug/20190704/1376823.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。