片段中的微调框在触摸时无反应

时间:2019-05-16 22:42:37

标签: android android-spinner

我有一个片段中的三个微调器。它们是从从远程服务器接收到的JSON填充的。

我可以看到所有三个微调器都有项目。

微调器是spinner_categoria,spinner_marca和spinner_modelo。

问题在于,只有spinner_marca和spinner_modelo被触摸时才显示其项目。

spinner_categoria显示了第一项,但是当触摸它时,什么也没有发生,而且我知道它还有另外三项。

这是我的代码:

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View v = inflater.inflate(R.layout.nuevo_disp_1, container, false);


        spinner_modelo = (Spinner) v.findViewById(R.id.spinner_modelos);

        layout_modelos = (LinearLayout) v.findViewById(R.id.layout_modelos);

        //CATEGORIAS
        txt_categoria = (TextView) v.findViewById(R.id.txt_categoria);
        spinner_categoria = (Spinner) v.findViewById(R.id.spinner_categorias);
        layout_categorias = (LinearLayout) v.findViewById(R.id.layout_categorias);

        adapterCategoria = new AdapterCategorias(getActivity(), listCategorias);
        spinner_categoria.setAdapter(adapterCategoria);

        spinner_categoria.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                // TODO Auto-generated method stub
                txt_categoria.setText("Categoría seleccionada : " + listCategorias.get(position).getNombre());
                layout_marcas.setVisibility(View.VISIBLE);

                callDataMarcas();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                // TODO Auto-generated method stub

            }
        });

        //MARCAS
        spinner_marca = (Spinner) v.findViewById(R.id.spinner_marcas);

        layout_marcas = (LinearLayout) v.findViewById(R.id.layout_marcas);

        txt_marca = (TextView) v.findViewById(R.id.txt_marca);
        spinner_marca = (Spinner) v.findViewById(R.id.spinner_marcas);
        layout_marcas.setVisibility(View.GONE);
        adapterMarca = new AdapterMarcas(getActivity(), listMarcas);
        spinner_marca.setAdapter(adapterMarca);
        spinner_marca.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                // TODO Auto-generated method stub
                txt_marca.setText("Marca seleccionada : " + listMarcas.get(position).getNombre());
                layout_modelos.setVisibility(View.VISIBLE);

                callDataModelos();

            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                // TODO Auto-generated method stub

            }
        });

        //MODELOS

        txt_modelo = (TextView) v.findViewById(R.id.txt_modelo);
        spinner_modelo = (Spinner) v.findViewById(R.id.spinner_modelos);
        adapterModelo = new AdapterModelos(getActivity(), listModelos);
        spinner_modelo.setAdapter(adapterModelo);




        spinner_modelo.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                // TODO Auto-generated method stub
                txt_modelo.setText("Modelo seleccionado : " + listModelos.get(position).getNombre());


            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                // TODO Auto-generated method stub

            }
        });




        callDataCategorias();



        return v;

    }

这是怎么回事?

编辑

片段中的XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:id="@+id/marcas"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/layout_categorias"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtbusqueda"
        android:layout_marginStart="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="10dp"
        android:layout_marginBottom="10dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Elige categoría:"
            android:textSize="20dp"
            android:textStyle="bold" />

        <Spinner
            android:id="@+id/spinner_categorias"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/txt_categoria"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="Categoría seleccionada:"
            android:textSize="14sp"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout_marcas"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/layout_categorias"
        android:layout_marginStart="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="10dp"
        android:layout_marginBottom="10dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Elige marca:"
            android:textSize="20dp"
            android:textStyle="bold" />

        <Spinner
            android:id="@+id/spinner_marcas"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/txt_marca"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="Marca seleccionada:"
            android:textSize="14sp"
            android:textStyle="bold" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/layout_modelos"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/layout_marcas"
        android:layout_marginStart="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="10dp"
        android:layout_marginBottom="10dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Elige modelo:"
            android:textSize="20dp"
            android:textStyle="bold" />

        <Spinner
            android:id="@+id/spinner_modelos"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/txt_modelo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="Modelo seleccionado:"
            android:textSize="14sp"
            android:textStyle="bold" />
    </LinearLayout>



</RelativeLayout>

0 个答案:

没有答案