Strange Spinner. How to fix it?

后端 未结 4 1345
离开以前
离开以前 2021-01-28 02:18

This is my code to populate the Spinner. It looks strange and ugly.

    @Override
    protected void onPostExecute(final List result) {
        Sys         


        
相关标签:
4条回答
  • 2021-01-28 02:26

    (SearchTopActivity.this, android.R.layout.simple_spinner_dropdown_item, new String[]{"test1", "test2"}) change this

    android.R.layout.simple_spinner_dropdown_item to android.R.layout.simple_spinner_item
    

    refer http://developer.android.com/resources/tutorials/views/hello-spinner.html

    0 讨论(0)
  • 2021-01-28 02:27

    I think that happens because of the layout file you use. Try to use:

    android.R.layout.simple_spinner_item
    
    0 讨论(0)
  • 2021-01-28 02:29

    I had the same problem, I just wrote my own adapter by extending BaseAdapter and implementing SpinnerAdapter. Also I wrote my one item layout :

        <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <TextView
            android:id="@+id/tvParticipantSpinnerName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
    </RelativeLayout>
    

    And the spinner behave normally.

    0 讨论(0)
  • 2021-01-28 02:44

    TRY THIS

    @Override
        protected void onPostExecute(final List<String> result) {
            System.out.println("Result: " + result);
        final String[] test = new String[] { "test1", "test2" };
    
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_dropdown_item_1line, test);
        countrySpinner.setAdapter(adapter);
    }
    and xml as::
    
    <Spinner
        android:id="@+id/countrySpinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    
    0 讨论(0)
提交回复
热议问题