开发者

How to know if a spinner item has been selected in android?

How can I know if an item开发者_Python百科 in spinner has been selected in android??


See here: http://developer.android.com/resources/tutorials/views/hello-spinner.html

You have to implement an OnItemSelectedListener.

Here the example from the link:

public class MyOnItemSelectedListener implements OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> parent,
        View view, int pos, long id) {
      Toast.makeText(parent.getContext()), "The planet is " +
          parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
    }

    public void onNothingSelected(AdapterView parent) {
      // Do nothing.
    }
}

spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

You could also use an anonymous inner method if you don't want to explicitly declare a class for your listener.


for the spinner, you need to implement OnItemSelectedListener.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜