0

comment contourner ce problème?se déplacer d'erreur 'ne peut pas résoudre le symbole'

Je veux montrer des toasts quand on clique sur l'aide imageview onclick auditeur.

principale 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[]{ 
      "[email protected]:hello", "[email protected]: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(); 
      } 

     }); 

    } 

l'erreur est ici:

mImageView.setOnClickListener (nouveau View.OnClickListener() {

@Override public void onClick (Voir affichage) { Toast.makeText (this, "done", Toast.LENGTH_SHORT) .show(); }

});

ne peut pas résoudre méthode 'maketext (anonyme ....)'

+1

Utiliser 'LoginActivity.this' au lieu de' this' comme premier paramètre à '' maketext –

+1

'Essayez Toast.makeText (LoginActivity.this, ....' – Titus

Répondre

1

Vous devez utiliser votre Activity context pas "this" Ex:

Toast.makeText(MainActivity.this, "Your message", Toast.LENGTH_LONG).show(); 

Vous êtes appelles contexte du bouton.

1

Utilisation LoginActivity.this au lieu de this comme premier paramètre à maketext

mImageView.setOnClickListener(new View.OnClickListener() { 

    @Override public void onClick(View view) { 
      Toast.makeText(LoginActivity.this,"done",Toast.LENGTH_SHORT).show(); } 
    }); 

espère que cela aidera!

0
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(); 
0

Essayez d'utiliser

Toast.makeText(LoginActivity.this, "Done", Toast.LENGTH_LONG).show();