android - when i call dynamic fragment from another fragment , i still could access buttons in the first fragment ؟ -
when 2nd fragment displayed if click made in-where button in 1st fragment exists(at position )- old button onclick got called, transparent button :), should no happen @ least replace() .note: first fragment fragment under tablayout.
public class first_fragment extends fragment { public first_fragment () { // required empty public constructor } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview=inflater.inflate(r.layout.profile_fragment, container, false); final view fragmentcontainer = rootview.findviewbyid(r.id.container); button new_frament_btn= (button)rootview.findviewbyid(r.id.new_frament_btn); new_frament_btn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { fragment newfragment = new second_fragment(); fragmenttransaction transaction = getfragmentmanager().begintransaction(); transaction.replace(fragmentcontainer.getid(), newfragment); transaction.addtobackstack(null); transaction.commit(); } }); button btn_toast= (button)rootview.findviewbyid(r.id.btn1); btn_toast.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { toast.maketext(getactivity(), "this first fragment", toast.length_long).show(); } }); return rootview; } }
the first fragment xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:background="@drawable/profile_background_yellow1" android:id="@+id/container" android:layout_height="match_parent" android:orientation="vertical"> <button android:id="@+id/new_frament_btn" android:layout_width="70dp" android:layout_height="70dp" android:layout_below="@+id/setting" android:layout_centerhorizontal="true" android:src="@drawable/profile_friends" /> <button android:id="@+id/btn1" android:layout_width="70dp" android:layout_height="70dp" android:layout_alignparentend="true" android:layout_alignparentright="true" android:layout_centervertical="true" android:src="@drawable/profile_account_setting"/> ............. />
the second fragment code
public class second_fragment extends fragment { public second_fragment () { // required empty public constructor } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment return inflater.inflate(r.layout.fragment_two, container, false); }
}
the second fragment xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" > <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerinparent="true" android:text="second_fragment" android:textsize="40dp" android:textstyle="bold" /> </relativelayout>
add android:clickable="true"
in xml file of second fragment layout. think gonna help.
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" />
Comments
Post a Comment