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

Go To StackoverFlow.com

0

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

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


0

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());
      }
}
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


0

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
Ads