how to delete a particular file from the paticular folder in sdcard when click on check boxes in list view

Go To


how to delete a particular file from the paticular folder in sdcard when click on check boxes in list view.

  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(;
        viewHolder.checkbox = (CheckBox) view.findViewById(;
        viewHolder.imageView=(ImageView) view.findViewById(;

        viewHolder.checkbox.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

        .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                Model element = (Model) viewHolder.checkbox

            //  list.remove(position);

                    Toast.makeText(getContext(), "Checked", 


    } else {
        view = convertView;
        ((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));

    ViewHolder holder = (ViewHolder) view.getTag();

    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???

2012-04-04 06:43
by user1312105
did you try googling "java file delete" - Snicolas 2012-04-04 06:53
i need to delete file when we check on check box and then click to button - user1312105 2012-04-04 06:58
do u have any idea?? - user1312105 2012-04-04 07:11


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() ) {
2012-04-04 07:27
by Shankar Agarwal
my need is, if i check a particular check box it should select that row and then if click on delete button that particular row should be deleted from folder of sdcard where it is fetching. - user1312105 2012-04-04 07:32


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.

2012-04-04 08:15
by Snicolas
how to delete file from the folder in sdcard when i get the position of that file in listview - user1312105 2012-04-04 08:57
don't you have a list of file that you use to fill data to your listadapter - Snicolas 2012-04-04 08:59
hey do u know how to delete a file from the folder in sdcard when u click in listview means by the position in list view can u delete it? - user1312105 2012-04-04 09:11
I can't follow you. If you have an index in a list, why can't you retrieve the file at that index in the list ?? - Snicolas 2012-04-04 09:18
can u give me a code if u have. - user1312105 2012-04-04 09:40