android spinner performClick onItemSelected

后端 未结 3 1448
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-19 09:22

I have a little problem with a spinner.

I create a Spinner the user click a Button. The Spinner is shown as it should be, but

相关标签:
3条回答
  • 2020-12-19 09:25

    Solved the problem by adding a Spinner in my xml with height and width set to zero.

    0 讨论(0)
  • 2020-12-19 09:25

    why do you have spinner = new Spinner(this) in the set-up ?

    surely you already have a Spinner in the XML of your layout, then you simply do spinner = (Spinner) findViewById(R.id.WHATEVER_THE_ID_IS_IN_THE_XML); so you don't need a new

    P.S. this is how I define a Spinner in an XML layout

    <Spinner
    android:id="@+id/SPINNER_ID"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:gravity="center_horizontal" />
    
    0 讨论(0)
  • 2020-12-19 09:38

    This looks enough like the turorial, so refer back to that. See below:

    I don't see this, but does the main class implement OnItemSelectedListener? Also, You'll want to instantiate the Spinner inside the onCreate() within the main class body.

    This line needs to be within the onCreate();

    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
    
    0 讨论(0)
提交回复
热议问题