2016-12-18 12 views
0

私はCHOICE_MODE_MULTIPLE_MODAL対応ListViewを持っています。 List Item XMLのRelativeLayout内にTextViewが1つだけ含まれている場合、リスト項目が長く選択されるようになっています。複数選択リストビューがリストアイテム内の複数のコンポーネントで機能しない

しかし、アイテム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

これは必須条件ではありません。チェックボックスのオン/オフは、リストアイテムの選択とは関係ありません。あなたはチェックボックスのチェックのように考えることができますリスト項目の選択として全体のリスト項目の削除を有効にするタスクを完了させる。 –

関連する問題