【发布时间】:2014-09-13 14:12:08
【问题描述】:
我有一个活动,其中有一个列表视图,其中包含文本视图和右侧的复选框。我希望在单击列表视图项时选中复选框。 (不在复选框上)。就像android用来一一检查要删除的消息一样。
谁能帮我解决这个问题?我关机了
android:focusable="false
和
android:focusableInTouchMode="false"
在复选框上。
下面是我的列表视图项 xml。
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="1."
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/white" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_toRightOf="@+id/textView2"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView1"
android:layout_marginRight="22dp"
android:layout_marginTop="-15dp"
android:focusable="false"
android:focusableInTouchMode="false"/>
这是我的代码:
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
// TODO Auto-generated method stub
if(checkbox.isChecked())
checkbox.setChecked(false);
else
checkbox.setChecked(true);
}
});
【问题讨论】:
-
请发布一些代码(XML 布局)。
-
请发布/分享代码(列表项的xml)!
-
考虑使用CheckedTextView(如
android.R.layout.simple_list_item_checked)或编写自定义可检查布局。 -
将此属性指定给您的主 RelativeLayout android:descendantFocusability="blocksDescendants"
-
你的列表视图在哪里?
标签: android android-listview android-checkbox