2 回答
TA贡献1877条经验 获得超1个赞
将以下行添加到微调器方法的顶部onItemSelected。
if(i==0){
///Here you need to show the error msg for the first item selected
Log.v("ERROR","Please select an item callded");
//return is used the break the flow of the app so the code below does not run in this case
return;
}
TA贡献1820条经验 获得超2个赞
在第一个位置添加您的项目。在 Spinner 上添加一个 Item Selected Check Listner 并添加一个检查是否选择的值是第一个。如果先显示消息
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// your code here
if(position==0)
Toast.makeText(getContext,"Please select a value",Toast.LENGTH_LONG).show()
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
添加回答
举报