Question

In mi layout I have 3 spinners. Each one implements onItemSelectedListener. The problem is when I select an option on spinner number 2 (spinnerSwitches) the spinner number 3 (spinnerVQs) is resizing itself, and i don´t want that to happen. I attached, Activity code, images, and xml layout

Activity:

public class CCHawkResourcesActivity extends Activity {

private Spinner spinnerTenants;
private Spinner spinnerSwitches;
private Spinner spinnerVQs;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cchawk_resources);
    vincularControles();
    Sesion.setUsuarioActual(RetornaLogica.GetInstance().getIl().TraerUsuarios().get(0));
    Tenant selectedTenant=new Tenant(Sesion.getUsuarioActual().getConfig().getSelectedTenant());



    ArrayAdapter<Tenant> a=new ArrayAdapter<Tenant>(this,R.layout.spinner_dropdown_item,Sesion.getListaTenants());
    a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerTenants.setAdapter(a);
    if(!selectedTenant.getNombre().equals(""))spinnerTenants.setSelection(a.getPosition(selectedTenant));
    spinnerTenants.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View selectedView,int position, long id) {

            Tenant t=((Tenant)spinnerTenants.getSelectedItem());
            Switch selectedSwitch=new Switch(Sesion.getUsuarioActual().getConfig().getSelectedSwitch());
            ArrayAdapter<Switch> b=new ArrayAdapter<Switch>(CCHawkResourcesActivity.this,R.layout.spinner_dropdown_item,t.getListaSwitch());
            b.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinnerSwitches.setAdapter(b);
            if(!selectedSwitch.getNombre().equals(""))spinnerSwitches.setSelection(b.getPosition(selectedSwitch));
            spinnerSwitches.setOnItemSelectedListener(new OnItemSelectedListener() {

                @Override
                public void onItemSelected(AdapterView<?> parent, View selectedView,int position, long id) {

                    Switch s=((Switch)spinnerSwitches.getSelectedItem());
                    VirtualQueue selectedVQ=new VirtualQueue(Sesion.getUsuarioActual().getConfig().getSeletedVQ());

                    ArrayAdapter<VirtualQueue> c=new ArrayAdapter<VirtualQueue>(CCHawkResourcesActivity.this,R.layout.spinner_dropdown_item,s.getListaVQ());
                    c.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    spinnerVQs.setAdapter(c);
                    if(!selectedVQ.getNombre().equals(""))spinnerVQs.setSelection(c.getPosition(selectedVQ));
                    spinnerVQs.setOnItemSelectedListener(new OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> parent, View selectedView,int position, long id) {}

                        @Override
                        public void onNothingSelected(AdapterView<?> arg0) {}
                    });


                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {}
            });

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {}
    });


}

private void vincularControles(){

    spinnerTenants=(Spinner)findViewById(R.id.spinnerTenants);
    spinnerSwitches=(Spinner)findViewById(R.id.spinnerSwitches);
    spinnerVQs=(Spinner)findViewById(R.id.spinnerVQs);

}

}

Activity Layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/extra_dark_grey"
android:orientation="vertical"
android:padding="20dp" >

<TextView
    android:id="@+id/select"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="5dp"
    android:text="@string/select"
    android:textColor="@color/skyblue"
    android:textSize="25sp"
    android:textStyle="bold" />

<TextView
    android:id="@+id/selectText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="20dp"
    android:text="@string/selectText"
    android:textColor="#FFFFFF"
    android:textSize="15sp" />

<Spinner
    android:id="@+id/spinnerTenants"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:prompt="@string/select_tenant" 
    android:spinnerMode="dialog"/>

<Spinner
    android:id="@+id/spinnerSwitches"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:prompt="@string/select_switch" 
    android:spinnerMode="dialog"/>


<Spinner
    android:id="@+id/spinnerVQs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:prompt="@string/select_vq" 
    android:spinnerMode="dialog"/>

<ImageButton
    android:id="@+id/btnPlus"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_gravity="right"
    android:layout_weight="2"
    android:background="#00000000"
    android:onClick="continueToStats"
    android:scaleType="fitEnd"
    android:src="@drawable/conf_right" />

Images

Before

After

Was it helpful?

Solution

I solved it, the thing you need to do is establish a height por each one of the linear layout containing the spinners, for example 60p, and establishing for each spinner a height smaller than the linear layout, for example 50dp

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top