2つの問題があります。
1つ目の問題。
私は CheckedTextView の "Select All" アイテムと、MutipleChoice のアダプターに設定された配列アイテムのリストを持っています。現在、CheckedTextView を選択して、配列項目のすべてのチェックボックスの状態を true/false に設定しようとしています。動作しますが、バグがあります。配列の最後の項目が true の場合、"SelectAll" を true にすると機能しますが、配列の最後の項目が false の場合は、すべての項目のチェックが外されます。私が望むのは、項目の状態のいずれかが false であっても、checkedtextview が true に選択されたときに true に設定されることです。
2番目の問題。
配列項目の状態がすべて true の場合、checkedtextview を true に設定できないようです。
私のやり方が間違っているのではないでしょうか?与えられた助けをいただければ幸いです..
これは、CheckedTextView「すべて選択」の私の方法です
private void markAll (Boolean state) {
for (int i = 0; i < lv.getCount(); i++) {
lv.setItemChecked(i, state);
}
}
これは、配列項目の状態を確認するためのコーディングです。
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
for(int i = 0; i < lv.getCount(); i++) {
//if even 1 of the item is false, the checkedtextview will be set to false
if(lv.isItemChecked(i) == false) {
ctv.setChecked(false);
}
//if all of the item is true, the checkedtextview will be set to true as well
//the coding should be done in the if-else below, if i'm not wrong
if(...) {
}
}
}
EDIT
これは私のメソッドを呼び出すための新しいコードです ctv.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
ctv.setClickable(true);
if(ctv.isPressed() && ctv.isChecked() == false) {
ctv.setChecked(true);
markAll(true);
}
else {
ctv.setChecked(false);
markAll(false);
}
}
});
これはcheckedtextviewの私のxmlコードです
<CheckedTextView
android:id="@+id/checkedtext"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:text="Select all"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:clickable="true"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft="6dip"
android:paddingRight="6dip"/>