有这个代码我只需要显示一个吐司,如果点击接受或取消,但不能理解为什么是错的
怎么修好?吐司错误getapplicationcontext()
我在android上了解对话框和吐司
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.widget.Toast;
public class confirmacion extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
AlertDialog.Builder builder= new AlertDialog.Builder(getActivity());
builder.setMessage("Confirmar?").setTitle("confirmacion")
.setPositiveButton("aceptar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("dialogos","aceptado");
dialog.cancel();
Toast.makeText(getApplicationContext(), "Eliminacion fallida.", Toast.LENGTH_LONG).show();
}
}).setNegativeButton("cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("dialogos","cancelada");
dialog.cancel();
}
});
return builder.create();
}
}
答案 0 :(得分:6)
从
改变Toast.makeText(getApplicationContext(), "Eliminacion fallida.", Toast.LENGTH_LONG).show();
到
Toast.makeText(getActivity(), "Eliminacion fallida.", Toast.LENGTH_LONG).show();