私はAndroid 3.1アプリケーションを開発しています。私はAndroid開発で非常に新しいです。次のように私はListActivity
定義されているカスタムListViewはnotifyDataSetChangedの後にすべてのチェックボックスをオフにしません
どのアイテム:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<CheckBox
android:id="@+id/itemCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
このListActivity
は、フォームのリストが表示されます。ユーザーは、1つまたは複数のフォームを選択して(そのcheckbox
をチェックして)ダウンロードすることができます。
フォームがダウンロードされるとき、私はそれらをリストから削除したいと思います。これを行うには、私はFormAdapter
でupdateFormsNotDownloaded
を使用します。
- フォーム1(チェック)
- フォーム2.
- フォーム3. :
public class FormAdapter extends ArrayAdapter<Form>
{
private Context context;
private int layoutResourceId;
private ArrayList<Form> forms;
private ArrayList<Integer> checkedItemsPosition;
private Button downloadButton;
public ArrayList<Integer> getCheckedItemsPosition()
{
return checkedItemsPosition;
}
public String[] getSelectedFormsId()
{
String[] ids = new String[checkedItemsPosition.size()];
int i = 0;
for(Integer pos : checkedItemsPosition)
{
Form f = forms.get(pos.intValue());
ids[i] = f.FormId;
i++;
}
return ids;
}
/**
* Called when selected forms has been downloaded and save it locally correctly.
*/
public void updateFormsNotDownloaded()
{
for(Integer pos: checkedItemsPosition)
remove(forms.get(pos.intValue()));
checkedItemsPosition.clear();
notifyDataSetChanged();
}
public FormAdapter(Context context, int textViewResourceId,
ArrayList<Form> objects, Button downloadButton)
{
super(context, textViewResourceId, objects);
this.context = context;
this.layoutResourceId = textViewResourceId;
this.forms = objects;
this.checkedItemsPosition = new ArrayList<Integer>();
this.downloadButton = downloadButton;
}
@Override
public int getCount()
{
return forms.size();
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
Log.v("FormAdapter", "getView.postion: " + position);
View row = convertView;
if (row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
}
Form f = forms.get(position);
if (f != null)
{
CheckBox checkBox = (CheckBox)row.findViewById(R.id.itemCheckBox);
if (checkBox != null)
{
checkBox.setText(f.Name);
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked)
{
//Form f = forms.get(position);
if (isChecked)
{
//checkedItems.add(f.FormId);
checkedItemsPosition.add(new Integer(position));
}
else
{
//checkedItems.remove(checkedItems.indexOf(f.FormId));
int index = checkedItemsPosition.indexOf(new Integer(position));
if (index > -1)
checkedItemsPosition.remove(index);
}
downloadButton.setEnabled(checkedItemsPosition.size() > 0);
}
});
}
}
return row;
}
}
}
は、私は次のリストを持っている想像してみて
ユーザーがフォーム1を選択し、フォームがローカルに保存され、updateFormsNotDownloaded
が呼び出されたときは、これを参照してください。
- フォーム2.(チェック)
- フォーム3.
フォーム2がチェックされているのはなぜ?どうすればすべてのチェックを外すことができますか?
このメイク感覚。私はそれを試し、結果をここに入力します。 – alicanbatur