Similar example I am posting hope it can help you. Whatever you are doing on check box same I am doing on delete button. If you want to do it with check box then you must maintain states of all checkboxes or atleast state of last selected checkbox. This is a custom adapter and I have override getView method. Look how I am display toast on button click in listview then you will understand. If still you are facing any problem then you can ask.
package com.example.list_view;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class array_adapter extends ArrayAdapter<String> {
Context context = null;
ArrayList<String> file_list = null;
public array_adapter(Context context, int textViewResourceId,
ArrayList<String> objects) {
super(context, textViewResourceId, objects);
this.context = context;
this.file_list = objects;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row_view = convertView;
if (row_view == null) {
row_view = View.inflate(context, R.layout.list_layout, null);
TextView text_view = (TextView) row_view.findViewById(R.id.textView1);
Button button = (Button) row_view.findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// POSITION YOU HAVE SO YOU CAN DO WHATEVER YOU WANT.
String file_name = file_list.get(position);
String MEDIA_PATH = new String(Environment.getExternalStorageDirectory() + "/AudioRecorder/" + file_name);
File file = new File(MEDIA_PATH);
file.delete();
file_list.remove(position);
notifyDataSetChanged()
// ATTACT FILE WITH CORRECT FILE PATH AND DELETE.
Toast.makeText(context, file_name, Toast.LENGTH_LONG).show();
}
});
text_view.setText(file_list.get(position));
}
return row_view;
}
}
If you are still facing any problem then you can ask.