Android-How to use Spinner in AlertDialog?

I have a spinner, how can I bind it to an AlertDialog? It can be done?

+5
source share
3 answers

try the following:

public class WvActivity extends Activity { TextView tx; String[] s = { "India ", "Arica", "India ", "Arica", "India ", "Arica", "India ", "Arica", "India ", "Arica" }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final ArrayAdapter<String> adp = new ArrayAdapter<String>(WvActivity.this, android.R.layout.simple_spinner_item, s); tx= (TextView)findViewById(R.id.txt1); final Spinner sp = new Spinner(WvActivity.this); sp.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); sp.setAdapter(adp); AlertDialog.Builder builder = new AlertDialog.Builder(WvActivity.this); builder.setView(sp); builder.create().show(); } } 
+15
source

Instead, why don't you use the action and set it in a dialog style. It should be similar to the same visual approach, and you can design your dialogue the way you want.

0
source

Can we add a spinner inside the method? If I tried this, showing a zero spin adapter. What to do.

0
source

Source: https://habr.com/ru/post/1394978/


All Articles