gpt4 book ai didi

android - 为什么我的 toast 不起作用?

转载 作者:太空宇宙 更新时间:2023-11-03 12:28:23 24 4
gpt4 key购买 nike

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.item_listview);

myspinner = (Spinner)findViewById(R.id.spinnertype);
String provider = myspinner.getSelectedItem().toString();

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, type_arrays,R.layout.support_simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
myspinner.setAdapter(adapter);

myspinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
Toast.makeText(parent.getContext(), "OnItemSelectedListener :" + parent.getItemAtPosition(pos).toString(), Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});

}
}

我尝试了不同种类的 toast ,但仍然没有出现。什么地方出了错?我查看了一些帖子,它说我不能将 onclicklistener 用于微调器

最佳答案

你试试这个,这可能对你有帮助

Toast.makeText(getApplicationContext(), "OnItemSelectedListener :" + parent.getItemAtPosition(pos).toString(), Toast.LENGTH_SHORT).show();

Toast.makeText(YourActivity.this, "OnItemSelectedListener :" + parent.getItemAtPosition(pos).toString(), Toast.LENGTH_SHORT).show();

关于android - 为什么我的 toast 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41549894/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com