android - new intent after click callback -


i have listview , when clicks on option want create new intent. menu item. first time working list views, i'm missing right way this, there easy fix?

private void registerclickcallback() {     listview list = (listview) findviewbyid(r.id.mainlist);     list.setonitemclicklistener(new adapterview.onitemclicklistener() {      @override     public void onitemclick(adapterview<?> parent, view viewclicked, int position, long id) {         textview textview = (textview) viewclicked;         toast.maketext(main.this, position, toast.length_short).show();         if(textview.gettext().tostring() == "my profile"){             intent intent = new intent(this.getapplicationcontext(), myprofile.class);             startactivity(intent);         }     } }); 

cannot resolve method 'getapplicationcontext'

you can't use this.getapplicationcontext() since you're inside new adapterview.onitemclicklistener() , there,this doesn't have method.

you should create class field containing application context , use or use viewclicked.getcontext() suggested @codemagic.

also, might have been read in comments, should use .equals string comparison. == operator not enough.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -