如何知道,如果一个微调项目已在Android中被选中?已在、项目、Android

2023-09-07 22:02:17 作者:昔日爱人i

我怎么能知道如果微调项目已在Android中被选中??

How can I know if an item in spinner has been selected in android??

推荐答案

在这里看到: http://developer.android.com/resources/tutorials/views/hello -spinner.html

您必须实施 OnItemSelectedListener

下面从链接的例子:

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.