android - how to use intent caller on button click properly? -



android - how to use intent caller on button click properly? -

actually bit confused on thing working in 1 scenario in other scenario not working fine here explain problem identify wrong move made me, if on identify problem please mention it. give thanks you.

working fine:

@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); findviewbyid(r.id.distance_demo_button).setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent intent = new intent(mainactivity.this, listviewclass.class); intent.putextra(listviewclass.extras_target_activity, distance.class.getname()); startactivity(intent); } });

not working fine:

scan = (button) view.findviewbyid(r.id.scan); scan.setonclicklistener(startlistener); } //create anonymous implementation of onclicklistener private onclicklistener startlistener = new onclicklistener() { public void onclick(view v) { toast.maketext(view.getcontext(),"scanning", toast.length_short).show(); intent intent = new intent(mainactivity.this, listviewclass.class); intent.putextra(listviewclass.extras_target_activity, distance.class.getname()); startactivity(intent); } }

now problem in line

intent intent = new intent(mainactivity.this, listviewclass.class);

when utilize line in scenario shows me error on line:

error: 'the constructor intent(mainactivity, class<listviewclass>) undefined' please mention problem if aware of it.

use global context variable glaboaly , utilize it.

context mycontext; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); mycontext = myactivity.this; }

and utilize mycontext insted of mainactivity.this. im not sure whether solve problem, seek out

android class android-intent

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -