我有一個活動,其中有一個列表視圖,其中包含文本視圖和右側的複選框。我希望複選框在點擊列表視圖項目時被選中。 (不在複選框上)。就像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佈局)。 – svenkapudija
請發佈/分享代碼(xml的列表項)! – arjoan
考慮使用[CheckedTextView](http://developer.android.com/reference/android/widget/CheckedTextView.html)(如'android.R.layout.simple_list_item_checked')或編寫自定義的可檢查佈局。 – Sam