![](/img/trans.png)
[英]How to toast an error message of validation shows that no item from a spinner is selected?
[英]How to get the toast from Spinner
我有一些問題得到一個Toast消息和Spinner選擇的文本也沒有被設置為微調器。 以下是無效的代碼。
category_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
showMessage("Selected "+position+"");
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
public void showMessage(String message)
{
Toast.makeText(Activity.this,message,Toast.LENGTH_SHORT).show();
}
嘗試用Activity.this
替換getApplicationContext()
,如下所示:
Toast.makeText(Activity.this,Toast.LENGTH_SHORT).show();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.