android - New layouts in TabHost -
i'm using tabhost in application in 1 of views (corresponding 1 of tabs) have button have take me activity , layout. question is: how new layout can continue have access tabs? or better say, how load new layout inside framelayout ?.
here have uploaded i'm trying do: http://imageshack.us/photo/my-images/541/exampleu.png/
thanks in advance.!
pd: i'm new in android, maybe there better way achieve purpouse without using tabactivity. i'm open suggestion.
edited: decided use fragments suggested. , have following:
- aplicationactivity extends fragmentactivity
- clientactivity extends fragment
- settingsactivity extends fragment
- dataclientactivity extends fragment
and following layouts:
- activity_aplicacion
- activity_client
- activity_settings
- activity_data_client
the activity_aplicacion.xml has tabhost, framelayout , tabwidget , these can go clientactivity , settingsactivity using tabs.
in clientactivity have button called "new" , when press button want go dataclientactivity. so, in clientactivity have te following:
public void onclicknew(view view){ dataclientactivity fragmentdataclient = new dataclientactivity (); final fragmenttransaction ft = getfragmentmanager().begintransaction(); ft.replace(android.r.id.tabcontent,fragmentdataclient , "fragmentdataclient "); ft.addtobackstack(null); ft.commit(); }
but when run app, got folling error:
05-04 21:55:04.780: e/androidruntime(7515): java.lang.illegalstateexception: not find method onclicknew(view) in activity class com.n.r.aplicationactivity onclick handler on view class android.widget.button id 'buttonnew'
so i'm little confuse rigth now. why should have onclicknew method in aplicationactivity , not in clientactivity have button?
edited 2: found solution this:
public class clientactivity extends fragment {
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // todo auto-generated method stub view view = inflater.inflate(r.layout.activity_clientes, container, false); **// register button.onclick event button b = (button)view.findviewbyid(r.id.buttonnew); b.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // toast.maketext(tab1fragment.this.getactivity(), "onclickme button clicked", toast.length_long).show(); log.e("onclicknuevo2 ", "inicio"); dataclientactivity fragmentdataclient= new dataclientactivity(); final fragmenttransaction ft = getfragmentmanager().begintransaction(); ft.replace(android.r.id.tabcontent,fragmentdataclient, "fragmentdataclient"); ft.addtobackstack(null); ft.commit(); } });** return view; }
}
i needed register onclick listener button inside clientactivity. every works perfectly!. divya motiwala :) , link: http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/#comment-410
you can use fragments
instead of activites inside tab. , on click of button, can replace existing fragment new 1 :
final fragmenttransaction ft = getfragmentmanager().begintransaction(); ft.replace(r.id.realtabcontent,newfrag, "new fragment"); ft.addtobackstack(null); ft.commit();
in ft.replace
1st parameter framelayout fragment attached, second fragment class object instatiated , third tag name.
Comments
Post a Comment