0

I've tried several ways to do this, I followed this -> Android Spinner databind using array list answer, but my object has an ArrayList inside. The whole thing is an ArrayList where Object has a list on his own.

How can I show this information properly? Another field in this class is something I don't want to be selectable, just the arraylist inside. The class definition will make everything clear:

public class Horario{
    private String fecha;
    private ArrayList<String> hora;

    public Horario(String _fecha, ArrayList<String> _hora){
        fecha=_fecha;
        hora = _hora;
    }

    public Horario(){}

    public void setFecha(String _fecha){
        fecha = _fecha;
    }
    public void setHora(ArrayList<String> _hora){
        hora=_hora;
    }

    public String getFecha(){
        return fecha;
    }
    public ArrayList<String> getHora(){
        return hora;
    }
}

This is a class for a schedule, the date (fecha) is what I dont want to be selectable, the hour (hora) is. I imagine this as a dropdown menu with categories (the date) and a group of clickable items (hours).

Date1
    hour 1
    hour 2
    hour 3
Date2
    hour 1

If this is difficult/impossible then I'm thinking of just listing the date + hour in each option of spinner.

Date1 - hour 1
Date1 - hour 2
Date1 - hour 3 ....

How can I achieve this? How can I personalize an adapter to get to this? Thanks in advance!

Community
  • 1
  • 1
Pundia
  • 161
  • 11
  • 1
    You're basically looking for a `ListView` with a sectioned adapter. There are a lot of tutorials for that. – user Nov 21 '12 at 19:37
  • @Luksprog: Something like that, but in spinner form? – Pundia Nov 21 '12 at 20:00
  • 1
    If I'm not mistaken a `Spinner` doesn't support different row types in it so the sectioned adapter it's not applicable. You can however use your second option, put the date in each of the rows and just use only one row type(all rows being selectable). – user Nov 21 '12 at 20:08

1 Answers1

1

EDIT:

I apologize, i think i understand what you had in mind now. i think what you want is for everything to be in the getDropDown view. I haven't exactly tested this but you could try for a get DropDownView that uses a different layout depending on how you wanna designate a marker for it. The kicker is that this custom layout has a selector xml that shows no difference.

public class HorarioArrayAdapter extends ArrayAdapter {

    private Horario horario;

    public HorarioArrayAdapter(Context context, int textViewResourceId, Horario horario) {
        super(context, textViewResourceId);
        this.horario = horario;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO whatever you had in mind
        return super.getView(position, convertView, parent);
    }


    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        View v;
        if (// marker at this position says something) {
            LayoutInflater viewInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = viewInflater.inflate(R.layout.custom_spinner_row, parent, false);   

            TextView text = (TextView) v.findViewById(R.id.txt_date);
            text.setText(horario.getHora().get(position));          
        } else {
            View v = super.getDropDownView(position, convertView, parent);
            TextView text = (TextView) v.findViewById(android.R.id.text1);
            text.setText(horario.getHora().get(position));              
        }
        return v;       
    }

}

The rub though would be making the spinner do nothing on the if those positions were clicked, as in not even close. You might need make a custom spinner for that takes in a int position array to tell it when to close or not close. i gotta say that it seems really involved for simply doing a display, and you might wanna consider compromises on this if you don't think it's worth it.

mango
  • 5,577
  • 4
  • 29
  • 41