나는 삭제하는 여러 항목을 선택 CheckBox
와 ListView
와 사용자 지정 레이아웃을 가지고 있지만 list.getCheckedItemPositions()
항상 내가 놓친 게 무엇인지 찾을 수 0안드로이드의 ListView는
반환합니다. 사용자가 CheckBox
을 true로 검사 할 때 체크 된 항목 목록을 채우려면 getCheckedItemPositions
이 반환하도록하려면 어떻게해야합니까?
리스트 뷰
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/footer"
android:choiceMode="multipleChoice"
android:clickable="true"
android:layout_below="@+id/adViewHolder" />
행
<LinearLayout
android:id="@+id/recording_play_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dip"
android:orientation="vertical" >
<ImageView
android:id="@+id/recording_play_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/play" />
<CheckBox
android:id="@+id/multi_checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:focusable="false"
android:focusableInTouchMode="false" />
</LinearLayout>
어댑터
public RecordingsAdapter(Context context, ListActivity a, ArrayList<MyObject> items) {
mContext = context;
mItems = items;
mActivity = a;
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
checkBoxState=new boolean[items.size()];
}
..................
................
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View vi = convertView;
if(convertView==null) {
vi = inflater.inflate(R.layout.recording_list_item, null);
}
final CheckBox multi_checkBox = (CheckBox) vi.findViewById (R.id.multi_checkBox);
multi_checkBox.setChecked(checkBoxState[position]);
multi_checkBox.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(((CheckBox)v).isChecked()) {
checkBoxState[position]=true;
v.setSelected(true);
} else{
checkBoxState[position]=false;
v.setSelected(false);
}
}
});
return vi;
}
활동
SparseBooleanArray checkedItemPositions = list.getCheckedItemPositions();
Log.i("recorded_file_delete list.getCheckedItemPositions()", String.valueOf(list.getCheckedItemPositions().size()));
int itemCount = list.getCount();
Log.i("recorded_file_delete", String.valueOf(itemCount));
for(int i=itemCount-1; i >= 0; i--){
if(checkedItemPositions.get(i)){
boolean deleted = f.delete();
if(deleted) {
Asr.recordingsCache.removeRecordingFile(f);
Log.i("recorded_file_delete", String.valueOf(deleted));
}
}
}
사용자 지정 행 레이아웃을 사용하는 경우이 메서드는 작동하지 않습니다. 하지만 부울 배열을 가지고 있습니다. 왜 그렇게 사용하지 않습니까? – Luksprog
어떻게 사용할 수 있습니까? 그것을 공개함으로써? – nLL
공개로 설정하거나 방법으로 공개 할 수 있습니다. – Luksprog