Not sure if it works with a CursorAdapter but
the following code does about the same as the UIPicker on iOS:
The code does the following:
- Create / get the data for the Spinner
- Use Buttons instead of Spinners on the activity
- Create an AlertDialog (pop-up) which displays the Spinner and an add-button
The add-button creates another popup with a EditText (text-field)
ArrayList<String> items = new ArrayList<String>(); items.add("One"); items.add("Two"); items.add("Three"); final ArrayAdapter<String> adapter = new ArrayAdapter<String>(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(); } });
Here are the resulting pictures:
Activity:
AlertDialog with Spinner and Button:
AlertDialog with text input: