Good afternoon guys, I have a question about Android. It consists in that I want to make a listView with multiple selection, so that when you select an item, change the background. I have that resolved, but I also want that multiple list to have headers, since it is a list of activities and these activities are grouped by categories. The problem is that when I group them by activities, they are no longer selected.
In case it is useful, I first make the selectable list without headers and create an activities_item with an "android: background=" @ drawable / selector "where selector is a drawable file that makes the functionality change the color according to the property of selected or not selected.
When I create the list with the header what I do is create the category object and create a custom Adapter for the activities where the getView is this:
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
Object o = (Object)items.get(position);
if(o instanceof Actividad2) {
if (convertView == null || convertView.findViewById(R.id.txtLan) == null){
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vi = inflater.inflate(R.layout.actividades_item, null);
}
Actividad2 actividad = (Actividad2) o;
final CheckedTextView nombreActividad = (CheckedTextView) vi.findViewById(R.id.txtLan);
nombreActividad.setText(actividad.getNombre());
final String[] pulsado = {"no"};
nombreActividad.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(final View view) {
/* ESTA COMENTADO
if(pulsado[0].equals("no")){
pulsado[0] = "si";
nombreActividad.setTextColor(activity.getResources().getColor(R.color.colorAccent));
nombreActividad.setTypeface(null, Typeface.BOLD_ITALIC);
}else{
pulsado[0] = "no";
nombreActividad.setTextColor(Color.GRAY);
nombreActividad.setTypeface(null, Typeface.BOLD_ITALIC);
}
FIN DEL COMENTARIO */
}
});
}else{
if (convertView == null || convertView.findViewById(R.id.textViewHeader) == null){
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vi = inflater.inflate(R.layout.categoria_item, null);
}
Categoria categoria = (Categoria)o;
TextView nombreCategoria = (TextView) vi.findViewById(R.id.textViewHeader);
nombreCategoria.setText(categoria.getNombre());
}
return vi;
}
As you can see, when it is a category, a layout is used and when it is an activity, another one is used, and in the commented part I tried that when an activity is selected because it changes the color view. but in that case it repeats itself and changes color in several items.
Finally comment that when I fill the list it is by means of a for I am doing a loop to collect the categories and then in another for to collect the activities of each category (I do not know if the for will have to do with the problem that is select several items).
Thank you very much for your answers in advance.