我正在尝试为Android编写一个简单的应用程序。如果在微调器中没有选择任何项目,我想显示吐司信息。 。我用两个进度条来做这个。我试过下面给出的代码。
String selection =sp.getSelectedItem().toString();
System.out.println("selected item "+selection);
if(selection=="[selection]")
Toast.makeText(getActivity(), "gfdgdghfhf", Toast.LENGTH_SHORT).show();
return false;
答案 0 :(得分:0)
use a string value as flag of selection
String status="not_selected";
yourSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
MyData d = items[position];
status=d.getValue();
}
public void onNothingSelected(AdapterView<?> parent) {
status="not_selected";
}
});
if(status.equqls("not_selected"){
//show toast here
}