Reputation: 380
I keep trying to compile this simple alert dialog to display when the user clicks the submit button. An error message pops up when the code is being compiled:
Error:(33, 74) error: incompatible types: <anonymous OnClickListener> cannot be converted to Context
This class is called Login_Activity, which extends BaseActivity, which extends 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.");
}
});
}
Upvotes: 2
Views: 2626
Reputation: 13288
change
AlertDialog.Builder messageBox = new AlertDialog.Builder(this);
to
AlertDialog.Builder messageBox = new AlertDialog.Builder(youractivityname.this);
Upvotes: 7