Checking if spinner is selected and having null value in Android

后端 未结 6 796
庸人自扰
庸人自扰 2021-01-12 09:27

I want to check first if spinner has null values based on the following:

String Name= spinnerName.getSelectedItem().toString();
if(Name != null) {     
} els         


        
6条回答
  •  不知归路
    2021-01-12 10:04

    Function for Spinner Item Selection

    SpinnerName.setOnItemSelectedListener(new OnItemSelectedListener() {             
                @Override
                public void onItemSelected(AdapterView adapter, View v,int position, long id) {
                    // On selecting a spinner item
                    selected_item = adapter.getItemAtPosition(position).toString();
                }
                @Override
                public void onNothingSelected(AdapterView arg0) {
                }
    });
    

    Check condition for selected Item

    if(selected_item.matches("")){
              //conditions accordingly  
    return;
    }
    

提交回复
热议问题