简体   繁体   中英

Spinner click not show drop down list

When run can see first item, but spinner click not show drop down list.

Why basic drop down list can not show?

In my another class the same way is worked, why this cannot?

I can change the selection by

sp_factory.setSelection(number);

,but click not show drop down list.

<LinearLayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F7FFEF"
    tools:context="com.fortune.activity.MF_schedule_activity">

    <Spinner
        android:id="@+id/sp_factory"
        android:layout_width="150dp"
        android:layout_height="200dp"
        android:layout_gravity="center"
        />
</LinearLayout>

code

    sp_factory = findViewById(R.id.sp_factory);
    ArrayAdapter<String> addressList = new ArrayAdapter<>(MF_schedule_activity.this,
            R.layout.layout_spinner, factory);
    addressList.setDropDownViewResource(R.layout.layout_dorpdown);
    sp_factory.setAdapter(addressList);
    sp_factory.setSelection(2);

Try this code:

       mSpinnerHeaderType = (Spinner) findViewById(R.id.spinner);
       String[] items = {Constants.TYPE_112R, Constants.TYPE_314R};
       ArrayAdapter<String> adapter = new ArrayAdapter<>(mContext, 
       android.R.layout.simple_spinner_item, items);
       mSpinnerHeaderType.setAdapter(adapter);

xml file:

<Spinner
         android:id="@+id/spinner"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:spinnerMode="dropdown"></Spinner>

check your 'factory' array is impty or not

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM