我试图将 toast 添加到我的应用程序活动中,以便当从微调器中选择项目时,所选项目名称会在 Toast 上弹出我们,这是我在所选项目上的代码。
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long id) {
Spinner spinner = (Spinner) findViewById(R.id.state_spinner);
spinner.setOnItemSelectedListener(this);
String state = adapterView.getItemAtPosition(pos).toString();
Toast.makeText(getApplicationContext(), state, Toast.LENGTH_LONG);
}
日志猫数据
W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
不要忘记在吐
司上调用show()
方法 - 如下所示:
Toast.makeText(view.getContext(), state, Toast.LENGTH_LONG).show();
尝试以下操作(您忘了在末尾添加show()
):
Toast.makeText(view.getContext(), state, Toast.LENGTH_LONG).show();