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!


4

1 回答 1

1

编辑:

对不起,我想我现在明白你的想法了。我认为您想要的是将所有内容都放在 getDropDown 视图中。我还没有完全测试过这个,但你可以尝试一个 get DropDownView ,它使用不同的布局,具体取决于你想如何为其指定一个标记。更重要的是,这个自定义布局有一个选择器 xml,没有任何区别。

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

}

但是,如果单击这些位置,则摩擦会使微调器不执行任何操作,甚至没有关闭。您可能需要制作一个自定义微调器,用于接收一个int position数组来告诉它何时关闭或不关闭。我得说,仅仅做一个展示似乎真的很重要,如果你认为这不值得,你可能想考虑妥协。

于 2012-11-21T20:34:50.120 回答