如何从Spinner烤面包

时间:2019-06-14 13:47:37

标签: java android

在获取祝酒消息时遇到一些问题,微调框选择的文本也没有设置为微调框。以下是无效的代码。

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();
    }

1 个答案:

答案 0 :(得分:0)

尝试将getApplicationContext()替换为Activity.this,如下所示:

 Toast.makeText(Activity.this,Toast.LENGTH_SHORT).show();