无法检查MaterialSpinner中选择的项目

时间:2019-05-02 07:46:32

标签: android spinner

我在一个活动中使用Material Spinner库。我无法检查用户在材料微调器中选择的选项/项目。

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。 日志猫:

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.

0 个答案:

没有答案