请参考这张图片dropbox.png
what i am doing :我正在创建一个list_view,在其中添加自定义适配器。
我用的是what i am using :,listView,customAdapter,菜单项。listView:整个应用程序中的单个列表视图customadapters:3个自定义适配器menuitem:1
How i am implementing :我有正确获取数据的数据库,从该数据库中,我通过过滤列表视图中的数据,在列表视图中输入了这些值:默认情况下输入的是第一种adapter_type (在onCreate中)。
adapter = new Adapter_forCompletedReminder( array_today_title , this) ;
ls.setAdapter(adapter) ;第二个adapter_type是通过按菜单在我的列表视图中输入的。
adapter = new Adapter_forCompletedReminder( array_past_2_day_title , this) ;
ls.setAdapter(adapter) ;3 adapter_type是通过按菜单项在我的列表视图中输入的。
adapter = new Adapter_forCompletedReminder( array_other_day_title , this) ;
ls.setAdapter(adapter) ;what is my problem :这段代码是在onCreate()方法中添加的。
ls.setOnItemClickListener( new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> adapterView , View view , int position ,long arg3)
{
Log.i("Item clicked","tushar:itemclicked") ;
}
});当我尝试实现AdapterView.OnItemClickListener()时,它不起作用.代码没有崩溃(日志猫中没有红线)。在单击llist_view_element时没有执行代码
谢谢你读了我的问题。
发布于 2013-06-04 10:24:47
在customview_completedxml_listview.xml中使用复选框,这就是onItemClick侦听器无法工作的原因。如果在复选框中设置clickable = "false“,那么onItemclick侦听器就能工作。
如果希望该复选框仍然有效,则必须在自定义适配器类中设置onclicklistener事件。
//我编辑getView
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = LayoutInflater.from(ob) ;
View v = inflater.inflate(R.layout.customview_completedxml_listview, null ) ;
TextView txt = ( TextView ) v.findViewById(R.id.txt_fordisplayingdata) ;
txt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(ob, "Hello", Toast.LENGTH_SHORT).show();
}
});
txt.setText(recieved_Array[position]) ;
return v ;
} /第二个解决方案在复选框中设置android:focusable="false“
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
>
<TextView
android:id="@+id/txt_fordisplayingdata"
android:layout_width="240dp"
android:text="display data"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
/>
<TextView
android:id="@+id/txt_fordisplayingLargerdata"
android:layout_width="240dp"
android:text="display data larger bahut larger "
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:visibility="gone"
/>
<View
android:layout_width="2dp"
android:layout_toRightOf="@id/txt_fordisplayingdata"
android:layout_height="15dp"
android:layout_marginLeft="15dp"
android:layout_centerVertical="true"
android:id="@+id/view_forcompletedtask"
/>
<CheckBox
android:layout_toRightOf="@id/view_forcompletedtask"
android:id="@+id/checkbox_tocomplete"
android:layout_marginLeft="15dp"
android:layout_width="wrap_content"
android:focusable="false"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
/>
</RelativeLayout>发布于 2013-06-04 09:25:49
以下是你可以尝试的几件事:-
发布于 2013-06-04 09:48:51
我真的说不出你到底有什么问题,但我给你写了一个很简单的例子。尝试它,如果它有效,只需将您当前的项目移植到我的示例项目中。kbYbVlyd1dvYTJZYTg/edit?usp=sharingalways
P.S.:我建议您在完成您的想法(关于ViewHolder模式)之后,阅读“Android中的最佳实践”。
https://stackoverflow.com/questions/16913783
复制相似问题