android - Can't use onClickImageListener on a Fragment swipetabs -


i've been trying add images fragment of swipe tab clicked open activity not yet working!

i have swipe tab activity has 3 fragments first intro second made menu , third information can't make menu want menu manually made image , clicked next relating activity inside it. me

fragment code:-

import android.content.intent; import android.os.bundle; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.imageview;   public class twofragment extends fragment { imageview img; public twofragment() {     // required empty public constructor }    @override public view oncreateview(layoutinflater inflater, viewgroup container,                          bundle savedinstancestate) {     return inflater.inflate(r.layout.fragment_two, container, false);     img = (imageview)getview().findviewbyid(r.id.imageview);     img.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             intent intent = new intent(twofragment.this, programming.class);             startactivity(intent);      }   });     } } 

adding images: image of fragment in image clicked

instead of twofragment.this first parameter of intent, pass getactivity() this:

@override     public void onclick(view v) {         intent intent = new intent(getactivity(), programming.class);         startactivity(intent);  } 

explanation: first parameter should of type context, why passing activity works, reason being activity extends context (indirectly). fragment not, hence passing fragment there not work.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -