OnItemClickListener没有与复选框工作? [英] OnItemClickListener was not work with the checkbox?

查看:106
本文介绍了OnItemClickListener没有与复选框工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目的布局类似这样的,并通过使用项目选择器设置背景

I have an item layout like this, and set the background by using item selector

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@drawable/itemselector"
android:orientation="horizontal" >
<CheckBox
    android:id="@+id/message_row_checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/message_row_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Title"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold"
        android:textColor="@color/black" />

itemselector.xml:

itemselector.xml :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item 
 android:state_pressed="true" 
 android:drawable="@color/yellow" />
<item 
 android:state_selected="true" 
 android:drawable="@color/green" />
<item 
 android:drawable="@color/white" />
</selector>

我有一个ListView这将内容的一些项目。然后我用setOnItemClickListener(),但它不工作。我发现,如果我去掉复选框中的项目,一切都将是欧凯。

I have a ListView which will content some items. Then I used setOnItemClickListener() but it doesn't work. I found that the if I remove the checkbox in the item, everything will be okey.

什么是复选框,并在此收​​听者之间的问题吗? 你能给我一些解决办法吗?

What was the problem between the checkbox and the listener here? Can you give me some solution?

更新:这是一个监听器的code

Update : This is the code of listener

mainListView.setAdapter(messageAdapter);
mainListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                        Message p = (Message) arg0.getItemAtPosition(arg2);
                        Toast.makeText(TarsiusActivity.this, p.getTitle(), Toast.LENGTH_LONG);
                        Log.i("Item Clicked", p.getTitle());
                    }
});

PS:我要让Gmail等Android上的收件箱。每一行都有一个复选框,用户可以点击项目,如果他们想看到的消息

ps: I want to make the inbox like gmail on android. Each row has a checkbox and user can click on item if they want to see the message

推荐答案

如果你有这样的按钮,ImageButton的,多选等在ListView任何clickables的onItemClickListener为ListView将无法正常工作。添加

The onItemClickListener for the listView will not work if you have any clickables like buttons, ImageButton, Checkbox, etc in the listView. Add

mainListView.setItemsCanFocus(true);

请参照<一href="http://stackoverflow.com/questions/2367936/listview-onitemclicklistener-not-responding">ListView OnItemClickListener不响应?

这篇关于OnItemClickListener没有与复选框工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆