绕过错误 'can not resolve symbol'
get around of error 'can not resolve symbol'
how to get around this issue?
我想在使用 onclick 单击 imageview 时显示 toast
听众.
主要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();
}
});
}
错误在这里:
mImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(this,"done",Toast.LENGTH_SHORT).show();
}
});
无法解析方法'maketext(anonymous ....)'
使用 LoginActivity.this
而不是 this
作为 makeText
的第一个参数
mImageView.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
Toast.makeText(LoginActivity.this,"done",Toast.LENGTH_SHORT).show(); }
});
希望对您有所帮助!
您需要使用 Activity context
而不是 "this"
例如:
Toast.makeText(MainActivity.this, "Your message", Toast.LENGTH_LONG).show();
您当前正在调用按钮的上下文。
Change
Toast.makeText(this,"done",Toast.LENGTH_SHORT).show();
to
Toast.makeText(getApplicationContext(),"done",Toast.LENGTH_SHORT).show();
or
Toast.makeText(LoginActivity.this,"done",Toast.LENGTH_SHORT).show();
尝试使用
Toast.makeText(LoginActivity.this, "Done", Toast.LENGTH_LONG).show();
how to get around this issue?
我想在使用 onclick 单击 imageview 时显示 toast 听众.
主要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();
}
});
}
错误在这里:
mImageView.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) { Toast.makeText(this,"done",Toast.LENGTH_SHORT).show(); }
});
无法解析方法'maketext(anonymous ....)'
使用 LoginActivity.this
而不是 this
作为 makeText
mImageView.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
Toast.makeText(LoginActivity.this,"done",Toast.LENGTH_SHORT).show(); }
});
希望对您有所帮助!
您需要使用 Activity context
而不是 "this"
例如:
Toast.makeText(MainActivity.this, "Your message", Toast.LENGTH_LONG).show();
您当前正在调用按钮的上下文。
Change
Toast.makeText(this,"done",Toast.LENGTH_SHORT).show();
to
Toast.makeText(getApplicationContext(),"done",Toast.LENGTH_SHORT).show();
or
Toast.makeText(LoginActivity.this,"done",Toast.LENGTH_SHORT).show();
尝试使用
Toast.makeText(LoginActivity.this, "Done", Toast.LENGTH_LONG).show();