开发者

Options Menu on Spinner

I'm looking for a way to add items to a spinner from within the spinner item list dialog.

Ideally, I could hit the menu button and select an option to add, prompt the user with an edittext dialog and update the item list. Is there a way to make the options menu accessible on a dialog?

I thought I might need to create an activity b开发者_运维知识库ut then how do I make it look like a spinner item list dialog and how would I get it to show up when the spinner is clicked?

All I'm trying to do is add an unobtrusive way to launch a prompt to add items to the spinner item list from within the dialog. Any ideas?


How about allowing them to long-click the list and handling the long click event?

Spinner s=(Spinner) findViewById(R.id.yourspinner); s.setOnLongClickListener(new OnLongClickListener(){}...

public class Main extends Activity {
/** Called when the activity is first created. */
private ArrayList<String> array_spinner;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Spinner s = (Spinner) findViewById(R.id.Spinner01);
    array_spinner=new ArrayList<String>();
    array_spinner.add("value");
    array_spinner.add("value 2");
    ArrayAdapter adapter = new ArrayAdapter(this,
    android.R.layout.simple_spinner_item, array_spinner);
    adapter.setNotifyOnChange(true);
    s.setAdapter(adapter);

    s.setLongClickable(true);
    s.setOnLongClickListener(new OnLongClickListener(){

        @Override
        public boolean onLongClick(View v) {
            // TODO Auto-generated method stub
            array_spinner.add("value 3");

            return false;

        }}
    );
}

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜