Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not sure if it works with a CursorAdapter but <br> <strong>the following code does about the same as the UIPicker</strong> on iOS:</p> <p>The code does the following:</p> <ol> <li>Create / get the data for the Spinner</li> <li>Use Buttons instead of Spinners on the activity</li> <li>Create an AlertDialog (pop-up) which displays the Spinner and an add-button</li> <li><p>The add-button creates another popup with a EditText (text-field)</p> <pre><code>ArrayList&lt;String&gt; items = new ArrayList&lt;String&gt;(); items.add("One"); items.add("Two"); items.add("Three"); final ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_dropdown_item, items); final Button selectBtn = (Button) findViewById(R.id.buttonCountry); selectBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(@SuppressWarnings("unused") View v) { new AlertDialog.Builder(main) .setTitle("Please choose a country") .setPositiveButton("Add Country", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final EditText view = new EditText(main); new AlertDialog.Builder(main) .setTitle("Please enter a name") .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { adapter.add(view.getText().toString()); selectBtn.setText(view.getText().toString()); } }) .setNegativeButton("cancel", null) .setView(view) .show(); } }) .setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { selectBtn.setText(adapter.getItem(which)); dialog.dismiss(); } }).create().show(); } }); </code></pre></li> </ol> <p>Here are the resulting pictures:</p> <p>Activity:<br> <img src="https://i.stack.imgur.com/cOrdb.png" alt="Activity"></p> <p>AlertDialog with Spinner and Button:<br> <img src="https://i.stack.imgur.com/Qqbhl.png" alt="AlertDialog with Spinner and Button"></p> <p>AlertDialog with text input:<br> <img src="https://i.stack.imgur.com/kMXB0.png" alt="AlertDialog with text input"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload