Problem with spinner in android studio

0

I have an application which loads from a database made with php / mysql a list of genres (musical and cinematographic) and loads them to a spinner, the problem is that it loads the elements wrong, the default background is white , but now also the letters of the elements are loaded in white which makes it difficult to read them, on the other hand in the emulator it lets me select them, but in the cell phone when I install the apk it does not let me select any element.

I have tried the second method that you put me and resulted in this

    
asked by Pedro Montenegro 11.11.2017 в 22:36
source

1 answer

0

Simple solution changes the color of the text and the size :

private OnItemSelectedListener OnCatSpinnerCL = new AdapterView.OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

       ((TextView) parent.getChildAt(0)).setTextColor(Color.BLUE);
       ((TextView) parent.getChildAt(0)).setTextSize(5);

    }

    public void onNothingSelected(AdapterView<?> parent) {

    }
};

Another more "complex" solution. Create a custom% XML file for your item.

spinner_item.xml:

Give your custom color and size to the text in this file.

<TextView  
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:gravity="left"  
    android:textColor="#FF0000"         
    android:padding="5dip"
    />

Now use this file to show your articles as:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_item,list);

You do not need to configure the pull-down resource. It will only take spinner_item.xml to show your items on the spinner.

    
answered by 11.11.2017 / 23:14
source