Spinner does not show selected value

后端 未结 25 1342
-上瘾入骨i
-上瘾入骨i 2020-12-03 13:16

I have implemented the spinner by populating the array list through database.I can get and show the array list in my spinner array adapter but if I select the item in spinne

相关标签:
25条回答
  • 2020-12-03 13:45

    For me the problem is that I was using getApplicationContext(). When I replace getApplicationContext() with this it works fine.

    ArrayAdapter<*> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, documentsCategories);
    
    0 讨论(0)
  • 2020-12-03 13:47

    Check these links:

    1. http://www.technotalkative.com/android-spinner-example/
    2. http://www.mkyong.com/android/android-spinner-drop-down-list-example/

    Else, try to store it on selecting the item:

    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    
                @Override
                public void onItemSelected(AdapterView<?> adapter, View v,
                        int position, long id) {
                    // On selecting a spinner item
                    String item = adapter.getItemAtPosition(position).toString();
    
                    // Showing selected spinner item
                    Toast.makeText(getApplicationContext(),
                            "Selected Country : " + item, Toast.LENGTH_LONG).show();
                }
    
                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                    // TODO Auto-generated method stub
    
                }
            });
    
    0 讨论(0)
  • 2020-12-03 13:47
    out_marginLeft="50dp"
                android:layout_marginTop="50dp"
                android:layout_marginRight="50dp"
                android:gravity="center"
                android:orientation="vertical">
    
                <ProgressBar
                    android:id="@+id/progressBar"
                    style="?android:attr/progressBarStyleHorizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_above="@+id/txtProgress"
                    android:layout_centerHorizontal="true"
                    android:layout_marginLeft="16dp"
                    android:layout_marginRight="16dp"
                    android:progress="50"
                    android:progressTint="@android:color/black" />
    
                <TextView
                    android:id="@+id/txtProgress"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:text="Progress"
                    android:textColor="@android:color/black" />
            </LinearLayout>  
    
    Java
    
    0 讨论(0)
  • 2020-12-03 13:49

    This answer may be a little stupid but try it. It worked for me.

    1. Check the background color of your spinner!
    2. And if it`s white change it
    3. Enjoy it!
    0 讨论(0)
  • 2020-12-03 13:49

    Problem:

    Spinner displays neither the default nor selected item value. But drop-down menu items are show when selected.

    Cause:

    Background and text color both being white!!!

    Solutions:

    xml(Preferable):

    Write a custom layout for a spiner item and use it instead of the default,android.R.layout.simple_spinner_item.

    How to change spinner text size and text color?

    Code(Less reliable):

    your_spinner_instance.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
        public void onItemSelected(AdapterView<?> parent, View view, int pos,
                                   long id) {
            ((TextView) view).setTextColor(Color.RED);
        }
        public void onNothingSelected(AdapterView<?> parent) {
        }
    
    });
    

    Android needs some major update or maybe dart and flutter should take over...

    Thanks Catluc

    0 讨论(0)
  • 2020-12-03 13:49

    if you have a custom adapter you should change the TextView text color

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView view = (TextView) super.getView(position, convertView, parent);
        view.setTextColor(Color.parseColor("#000000"));
        return view;
    }
    

    and if you don't have a custom adapter you should just change spinner background

    0 讨论(0)
提交回复
热议问题