android - How to start an activity from an image button which is there in a fragment of a navigation drawer -
i'm have implemented navigation drawer fragments, i'm trying open activity fragments. there many fragments i'm posting 1 of them on here i.e us, wanna start activity or fragment (whichever more simple) on click of image button.
aboutus.java
package hind.jai.com.jaihind; import android.app.actionbar; import android.app.fragment; import android.content.intent; import android.os.bundle; import android.support.v4.app.fragmentactivity; import android.support.v4.app.fragmenttabhost; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.button; import android.widget.imagebutton; import android.widget.imageview; /** * created sukhvir on 17/04/2015. */ public class extends android.support.v4.app.fragment { imagebutton img; public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate( r.layout.about, container, false); } @override public void onactivitycreated( bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); //get button view img = (imagebutton) getview().findviewbyid(r.id.imagebutton); //set onclick listener when button gets clicked img.setonclicklistener(new view.onclicklistener() { //start new list activity public void onclick(view v) { intent mainintent = new intent(getactivity(), abcd.class); } }); } }
about.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/about" android:id="@+id/textview" android:layout_gravity="center_horizontal" /> <imagebutton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imagebutton" android:background="@drawable/image2" android:onclick="onclick" android:layout_gravity="center_horizontal" /> </linearlayout>
and mentioned trying start new activity "abcd".
abcd.java
package hind.jai.com.jaihind; import android.app.activity; import android.os.bundle; /** * created rishik on 14-06-2015. */ public class abcd extends activity { protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.abcd); } }
abcd.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="new text" android:id="@+id/textview9" android:layout_gravity="center_vertical" /> </linearlayout>
when run project, works without crashes when click on image, doesn't start's new activity.
thanks lot in advance.
in onclick missing start activity intent
intent mainintent = new intent(getactivity(), abcd.class); startactivity(mainintent); // <-- missing
Comments
Post a Comment