我一直在尝试编译这个简单的警告对话框,以便在用户点击提交按钮时显示。编译代码时会弹出一条错误消息:
错误:(33,74)错误:不兼容的类型:<匿名OnClickListener>无法转换为上下文
此类称为Login_Activity,它扩展了BaseActivity,扩展了Activity。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mUserNameEt = (EditText) findViewById(R.id.login_username_et);
mPasswordEt = (EditText) findViewById(R.id.login_password_et);
mSubmitBtn = (Button) findViewById(R.id.login_submit_btn);
mSubmitBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder messageBox = new AlertDialog.Builder(this);
messageBox.setTitle("Atlas Box");
messageBox.setMessage("Dictionary.");
}
});
}
答案 0 :(得分:5)
更改
AlertDialog.Builder messageBox = new AlertDialog.Builder(this);
到
AlertDialog.Builder messageBox = new AlertDialog.Builder(youractivityname.this);