Android 老一套:你的听者就是不工作
MyAndroid 老一套:你的听者就是不工作,android,xml,listview,android-listview,Android,Xml,Listview,Android Listview,MyOnItemClickListener不适用于MyListView 我是这样设置的: ChatAdapter ca = new ChatAdapter(this, chatProfileList); chatListView.setAdapter(ca); chatListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&l
OnItemClickListener
不适用于MyListView
我是这样设置的:
ChatAdapter ca = new ChatAdapter(this, chatProfileList);
chatListView.setAdapter(ca);
chatListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Toast.makeText(ChatAct.this, "Yay its clicked.", Toast.LENGTH_LONG).show();
}
});
我的列表项目视图.xml:
不包含任何请求焦点或具有任何可单击内容的视图
E D I T 2:
正如你们中的一些人所建议的那样,我一个接一个地删除了我的元素,现在我得到了一个单一的线性布局。仍然不起作用
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/chat_list_item_backgroun"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#123"
android:orientation="horizontal"
>
如果列表中膨胀视图中的一个元素接收到触摸事件(
onClick
,onKeyDown
等),它将在到达列表项之前被消耗掉,因此监听器将不会被调用我发现有时候我的祝酒器也不起作用。尝试一个Log.d(标签,日志)在onClick
list_item.xml源和getView()/bindView()/适配器的其他“获取视图”自定义中的code>(我认为问题不在于“可单击”视图,而在于“窃取焦点”-视图可能是编辑文本或在getView中设置单击侦听器…)。。。现在这个问题无法回答(它从me:P开始工作)和离题(这个问题似乎离题了,因为它缺乏足够的信息来诊断问题)。请尝试设置不同的列表项布局。如果有效,请尝试删除元素,直到找到阻塞的元素。您使用哪种适配器?你能给我一些密码吗?
<ImageView
android:id="@+id/chat_profile_iv"
android:layout_width="51dp"
android:layout_height="70dp"
android:layout_marginRight="7dp"
android:focusable="false"
android:src="@drawable/male1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="7dp"
android:layout_weight="1"
android:focusable="false"
android:orientation="vertical" >
<hu.illion.sporttech.views.other.SportTechTextView
android:id="@+id/chat_name_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="false"
android:ellipsize="end"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center|left"
android:text="Ez egy név itt"
android:textColor="#fff"
android:textSize="18sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="false" >
<ImageView
android:id="@+id/chat_online_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:focusable="false"
android:src="@drawable/online" />
<TextView
android:id="@+id/chat_online_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="3dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Online"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#68ff5d" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:focusable="false"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="false" >
<TextView
android:id="@+id/chat_bubi_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:focusable="false"
android:text="0"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#8b8b8b"
android:textSize="12sp" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:focusable="false" >
<ImageView
android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:src="@drawable/chatke" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="false" >
<TextView
android:id="@+id/chat_naptar_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="0"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#8b8b8b"
android:textSize="12sp" />
<ImageView
android:id="@+id/chat_sched_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:focusable="false"
android:src="@drawable/naptarka" />
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/chat_list_item_backgroun"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#123"
android:orientation="horizontal"
>