2016-12-18 21 views
0

我有一个启用CHOICE_MODE_MULTIPLE_MODAL的ListView。它工作得很好,只要在列表项XML中的RelativeLayout中只包含一个TextView,就会长时间选择列表项。多选列表视图不能在列表项中使用多个组件

但是,当我添加一个复选框的项目XML然后我无法选择列表项目与长按。 任何帮助将不胜感激。

工作表的项目XML

<?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="match_parent" 
    android:background="@drawable/list_item_selector"> 

    <TextView 
     android:text="TextView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/todoNoteTitle" 
     android:layout_alignParentTop="true" 
     android:textSize="18sp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:paddingTop="20dp" 
     android:paddingBottom="20dp" 
     android:paddingLeft="10dp" /> 
</RelativeLayout> 

非工作表的项目XML

<?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="match_parent" 
    android:background="@drawable/list_item_selector"> 

    <TextView 
     android:text="TextView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/todoNoteTitle" 
     android:layout_alignParentTop="true" 
     android:textSize="18sp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:paddingTop="20dp" 
     android:paddingBottom="20dp" 
     android:paddingLeft="10dp" /> 
    <CheckBox 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/checkboxTodo" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 
     android:textSize="18sp" 
     android:paddingTop="20dp" 
     android:paddingBottom="20dp" 
     android:paddingRight="20dp"/> 

</RelativeLayout> 

任何线索?

回答

0

这样做:

your_text_view.setOnLongClickListener(new View.OnLongClickListener() { 
     @Override 
     public boolean onLongClick(View view) { 
      //Check or uncheck the CheckBox. 
      if (!your_check_box.isCheck()) 
       your_check_box.setChecked(true); 
      else your_check_box.setChecked(false); 

      return false; 
     } 
}); 

听长按(长点击这里)和长按事件设置当前复选框或取消它。这应该可以解决问题。

+0

不,这不是要求。复选框选中/取消选中与列表项选择无关。你可以考虑像复选框检查将使任务完成,因为列表项选择将启用删除整个列表项。 –