how to get around this issue?
i want to show toast when imageview is clicked using onclick listener.
main activity.java:
public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<Cursor> {
/**
* Id to identity READ_CONTACTS permission request.
*/
private static final int REQUEST_READ_CONTACTS = 0;
/**
* A dummy authentication store containing known user names and passwords.
* TODO: remove after connecting to a real authentication system.
*/
private static final String[] DUMMY_CREDENTIALS = new String[]{
"foo@example.com:hello", "bar@example.com:world"
};
/**
* Keep track of the login task to ensure we can cancel it if requested.
*/
private UserLoginTask mAuthTask = null;
ObjectAnimator objectAnimator=new ObjectAnimator();
// UI references.
public AutoCompleteTextView mEmailView;
public EditText mPasswordView;
private View mProgressView;
private View mLoginFormView;
@Override
protected void onCreate(Bundle savedInstanceState) {
FacebookSdk.sdkInitialize(this.getApplicationContext());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// Set up the login form.
mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
populateAutoComplete();
ImageView mImageView= (ImageView) findViewById(R.id.imageView);
mPasswordView = (EditText) findViewById(R.id.password);
mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
if (id == R.id.login || id == EditorInfo.IME_NULL) {
attemptLogin();
return true;
}
return false;
}
});
Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);
mEmailSignInButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
attemptLogin();
}
});
mLoginFormView = findViewById(R.id.login_form);
mProgressView = findViewById(R.id.login_progress);
Profile profile = Profile.getCurrentProfile().getCurrentProfile();
if (profile != null) {
// user has logged in
} else {
// user has not logged in
}
// SpellCheckerService.Session;//.openActiveSession(this, true, new SpellCheckerService.Session.StatusCallback() {
// callback when session changes state
// @Override
// public void call(SpellCheckerService.Session session, SessionState state, Exception exception) {
// }
// });
mImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(this,"done",Toast.LENGTH_SHORT).show();
}
});
}
the error is here:
mImageView.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) { Toast.makeText(this,"done",Toast.LENGTH_SHORT).show(); }
});
can not resolve method 'maketext(anonymous ....)'
You need to use your Activity context
not "this"
For ex:
Toast.makeText(MainActivity.this, "Your message", Toast.LENGTH_LONG).show();
You are currently calling context of the button.