how to delete a particular file from the paticular folder in sdcard when click on check boxes in list view.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.rowbuttonlayout, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.label);
viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
viewHolder.imageView=(ImageView) view.findViewById(R.id.imageView1);
viewHolder.imageView.setImageResource(R.drawable.ic_launcher);
viewHolder.checkbox.setChecked(true);
viewHolder.checkbox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("checkeddddd","checkedddddd2222222233333333444444");
}
});
viewHolder.checkbox
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
Model element = (Model) viewHolder.checkbox
.getTag();
element.setSelected(buttonView.isChecked());
InterectiveArrayAdapter.this.remove(InterectiveArrayAdapter.this.getItem(position));
//adapter.notifyDataSetChanged();
// list.remove(position);
Toast.makeText(getContext(), "Checked",
Toast.LENGTH_SHORT).show();
}
});
view.setTag(viewHolder);
viewHolder.checkbox.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
Log.i("checkeddddd","checkedddddd2222222233333333");
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getName());
holder.checkbox.setChecked(list.get(position).isSelected());
return view;
}
this is my adapter class i have customize my adapter class and i have put check boxes in adapter class to show in listview and the data in listview is coming from the folder in sdcard i need to check a particular check box and the click on the button then that particular file should be deleted from the folder in sdcard. how can i do it???
If you have path to the particular file then you can delete it by calling the below method().::
public boolean deleteFile(File path) {
// TODO Auto-generated method stub
if( path.exists() ) {
return(path.delete());
}
}
In get view, put the first param position as final. Then you will be able to get it from the OnCheckListener. Then, you can save it in some list. And when the button is clicked, loop through the list and delete files.