如何显示类别&微调器中的子类别

时间:2015-10-14 12:18:40

标签: android spinner categories

enter image description here

我是Android编程的新手。我需要找到微调器中所选类别的值。如果项目具有子类别,则它应显示在微调器2中,否则不显示。通过选择类别,应显示相应的值。我需要附图中的内容。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

主要功能

String[] strings = {"Pilot", "Flight Attendant",
        "Technical"};
Spinner mySpinner = (Spinner)findViewById(R.id.spinner);
    mySpinner.setAdapter(new MyAdapter(NewMember.this, R.layout.row, strings));

我的适配器功能

public class MyAdapter extends ArrayAdapter<String> {

    public MyAdapter(Context context, int textViewResourceId,   String[] objects) {
        super(context, textViewResourceId, objects);
    }

    @Override
    public View getDropDownView(int position, View convertView,ViewGroup parent) {
        return getCustomView(position, convertView, parent);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getCustomView(position, convertView, parent);
    }

    public View getCustomView(int position, View convertView, ViewGroup parent) {

        LayoutInflater inflater=getLayoutInflater();
        View row=inflater.inflate(R.layout.row, parent, false);
        label =(TextView)row.findViewById(R.id.company);
        label.setText(strings[position]);


        if(label.getText().toString().contains("something"))
        {
           //do anything

        }

        return row;
    }
}