我正在活动中使用材质微调器库。我无法检查用户在材质微调器中选择的选项/项目。
https://github.com/jaredrummler/MaterialSpinner
我按照上面GitHub链接中的说明操作
我想我的问题与此类似。https://github.com/jaredrummler/MaterialSpinner/issues/36
public class ChooseStateRoleName extends AppCompatActivity {
List<Agm_Data> agm_data = new ArrayList<>();
MaterialSpinner stateSpinner, roleSpinner, nameSpinner;
Button nextButton;
private int selectedState;
private int selectedRole;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_state_role_name);
String[] STATES = {"Karnataka", "Andra Pradesh","Tamil Nadu", "Kerala", "Goa", "Maharastra", "Gujarat", "Orissa", "Madhya Pradesh", "Rajastan", "Jharkand", "Bihar", "Uttar Pradesh", "West Bengal", "Haryana", "Punjab", "Assam", "Meghalaya", "Tripura"};
String[] ROLES = {"AGM", "TGE", "DP"};
final ArrayAdapter<String> stateAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, STATES);
ArrayAdapter<String> roleAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ROLES);
stateAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
roleAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
stateSpinner = (MaterialSpinner) findViewById(R.id.select_state_spinner);
roleSpinner = (MaterialSpinner) findViewById(R.id.select_role_spinner);
nameSpinner = (MaterialSpinner) findViewById(R.id.select_name_spinner);
nextButton = (Button) findViewById(R.id.next);
stateSpinner.setAdapter(stateAdapter);
roleSpinner.setAdapter(roleAdapter);
stateSpinner.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener() {
@Override
public void onItemSelected(MaterialSpinner view, int position, long id, Object item) {
selectedState = view.getSelectedIndex();
Log.v("Selected state: ", String.valueOf(selectedState));
});
}
在微调器中选择一个项目后,立即会看到如下所示的logcat。logcat:
I/OpenGLRenderer: Initialized EGL, version 1.4
W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
1条答案
按热度按时间tyg4sfes1#
有两种方法:
1.试试这个:选择状态=字符串.值为(状态旋转器.获取选择索引());
这将给你和int,你可以很容易地使用。
1.或者这个:选定状态=项目;