Gracias Ramon por tu respuesta, eres un crack!
Lo que no sé es cómo solucionar el error. En el enlace que me pasaste no viene una solución a mi caso.
Aquí pongo un vídeo que he hecho de lo que pasa para que se vea mejor
http://www.dailymotion.com/video/x2iu5mn_aplication_tech
Este es el código del custom_view (custom_textview2.xml)al que llama el arrayadapter personalizado
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkBox1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/text1"/>
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="@+id/imageView"
android:src="@android:drawable/ic_menu_add"
/>
</LinearLayout>
Este es mi arrayadapter
private class myArrayAdapter2 extends ArrayAdapter<String>{
private HashMap<Integer, Boolean> myChecked = new HashMap<Integer, Boolean>();
public myArrayAdapter2(Context context, int resource, int textViewResourceId, List<String> objects) {
super(context, resource, textViewResourceId, objects);
for(int i = 0; i < objects.size(); i++){
myChecked.put(i, false);
}
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
if(row==null){
LayoutInflater inflater=getLayoutInflater();
row=inflater.inflate(R.layout.custom_textview2, parent, false);
}
TextView textview = (TextView)row.findViewById(R.id.text1);
textview.setText(myList.get(position));
CheckBox checkBox=(CheckBox) row.findViewById(R.id.checkBox1);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
ruta.add(Environment.getExternalStorageDirectory().getPath() + "/test/"+myList.get(position));
}else{
//busco la palabra deseleccionada(su id) y guardo la posicion en la variable
shared=ruta.indexOf(Environment.getExternalStorageDirectory().getPath() + "/test/"+myList.get(position));
//ahora si que puedo borrar la posicion de la id seleccionada y asi elimino la palabra
ruta.remove(shared);
}
}
});
return row;
}
}
Y este es el evento que rellena el listview cuando pulso el boton audios:
public void AudioClick(View view) {
File file = new File(Environment.getExternalStorageDirectory().getPath()+"/test");
List<String> myList = new ArrayList<String>();
File list[] = file.listFiles();
//meto los elementos del directorio(sus nombres completos) en la lista de strings
for( int i=0; i< list.length; i++)
{
myList.add( list[i].getName() );
}
//con esto metemos los nombre de los audios en un listview
ArrayAdapter myArrayAdapter = new MyArrayAdapter(
this,
R.layout.custom_textview,
android.R.id.text1,
myList
);
//seteamos el listview
lista.setAdapter(myArrayAdapter);
}