Android 为什么Toast.makeText不接受格式化文本?

Android 为什么Toast.makeText不接受格式化文本?,android,android-studio,toast,Android,Android Studio,Toast,作为android中的乞丐,我在使用Toast.makeText时遇到了麻烦,下面是代码 public class CustomOnSelectedListen implements OnItemSelectedListener{ public void onItemSelected(AdapterView<?> parent, View view,int pos,long id){ Toast.makeText(parent.getContext(),

作为android中的乞丐,我在使用Toast.makeText时遇到了麻烦,下面是代码

public class CustomOnSelectedListen implements OnItemSelectedListener{

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

 public void onNothingSelected(AdapterView<?> arg0){
     Toast.makeText(CustomOnSelectedListen.this,"Please select place and class".toString(),Toast.LENGTH_SHORT).show();
 }
此处无法转换CustomOnSelectedListen,可能有什么问题


编辑1:是CustomOnSelectedListen不是上下文实例,我需要使用toast在函数onNothingSelected()中显示消息,有什么不同的方法

在您的
onNothingSelected
功能上:

Toast.makeText(CustomOnSelectedListen.this,"Please select place and class".toString(),Toast.LENGTH_SHORT).show();

第一个参数(
CustomOnSelectedListen.this
)不是
Context
实例。

CustomOnSelectedListen无法转换为Context获取提示..检查顶部的直接子类和间接子类@。您需要将Context实例作为makeText方法中的第一个参数传递,不是CustomOnSelectedListen实例。在哪个类中打印此实例?
Toast.makeText(CustomOnSelectedListen.this,"Please select place and class".toString(),Toast.LENGTH_SHORT).show();