2 回答

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超1個(gè)贊
將以下行添加到微調(diào)器方法的頂部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貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超2個(gè)贊
在第一個(gè)位置添加您的項(xiàng)目。在 Spinner 上添加一個(gè) Item Selected Check Listner 并添加一個(gè)檢查是否選擇的值是第一個(gè)。如果先顯示消息
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
}
});
添加回答
舉報(bào)