如何制作使用字符串作为消息的 onItemClickListener? 我正在制作支持多种语言的应用程序,我想用不同的语言来展示 toast 。为此,我需要使用字符串。那么如何获取 toast 的字符串并显示它呢?
list.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
switch (position) {
case 0:
showtost();
break;
}
return true;
我尝试了一些方法,但没有用。
private void showtost() {
// TODO Auto-generated method stub
Toast.makeText(this,
.getResources().getString(R.string.alarm),
Toast.LENGTH_SHORT).show();
return;
}
The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new AdapterView.OnItemLongClickListener(){},
字符串,整数)
最佳答案
您需要将 this
更改为对上下文的引用,例如如果在 Activity 中使用:
MyActivity.this
或在 fragment 内使用:
getActivity()
然后您发布的示例将起作用。
关于android - Toast onItemClickListener 使用字符串作为消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22786237/