No, I wasn't waiting for the answer ^^

As far as I remember I was trying to remove a fragment from the hierarchy,
so just hiding it is not a solution. But this is not my problem anymore.


2013/9/24 Piren <[email protected]>

> I hope he was not still waiting for that answer.
>
>
> On Tuesday, September 24, 2013 3:39:14 PM UTC+3, Adarsh Pandey wrote:
>>
>> use
>>
>> findViewById(R.id.fragment).**setVisibility(View.GONE);
>>
>> On Wednesday, March 9, 2011 3:34:31 PM UTC+5:30, clemp6r wrote:
>>>
>>> Hi,
>>>
>>> I can't remove a Fragment that was added in an XML layout file, using
>>> a FragmentTransaction. I don't understand why, I probably
>>> misunderstood something and I would appreciate some explanations.
>>>
>>> ----
>>> Here's a simple code to demonstrate my problem :
>>>
>>>     ** Main layout, main.xml:
>>>     <LinearLayout 
>>> xmlns:android="http://schemas.**android.com/apk/res/<http://schemas.android.com/apk/res/>
>>> android"
>>>         android:orientation="vertical"
>>> android:layout_width="fill_**parent" android:layout_height="fill_**parent"
>>>
>>>         android:id="@+id/root"
>>>         >
>>>         <TextView android:id="@+id/hello_view"
>>>             android:layout_width="fill_**parent"
>>>             android:layout_height="wrap_**content"
>>>             android:text="@string/hello"
>>>         />
>>>
>>>         <fragment android:name="test.fragments.**FragmentA"
>>>             android:id="@+id/fragment_a"
>>>             android:layout_width="fill_**parent"
>>>             android:layout_height="wrap_**content"
>>>         />
>>>     </LinearLayout>
>>>
>>>     ** Main activity:
>>>     public class TestFragmentsActivity extends Activity {
>>>
>>>         @Override
>>>         public void onCreate(Bundle savedInstanceState) {
>>>             super.onCreate(**savedInstanceState);
>>>             setContentView(R.layout.main);
>>>
>>>             TextView helloView = (TextView)
>>> findViewById(R.id.hello_view);
>>>             helloView.setOnClickListener(**new OnClickListener() {
>>>
>>>                 @Override
>>>                 public void onClick(View v) {
>>>                     FragmentManager fragmentManager =
>>> getFragmentManager();
>>>                     FragmentTransaction transaction =
>>> fragmentManager.**beginTransaction();
>>>
>>> transaction.remove(**fragmentManager.**findFragmentById(R.id.**fragment_a));
>>>
>>>                     transaction.commit();
>>>                 }
>>>             });
>>>         }
>>>     }
>>>
>>>     ** My fragment class:
>>>     public class FragmentA extends Fragment {
>>>
>>>         @Override
>>>         public View onCreateView(LayoutInflater inflater, ViewGroup
>>> container, Bundle savedInstanceState) {
>>>             return inflater.inflate(R.layout.**layout_a, container,
>>> false);
>>>         }
>>>     }
>>>
>>>     ** Fragment layout, layout_a.xml:
>>>     <LinearLayout 
>>> xmlns:android="http://schemas.**android.com/apk/res/<http://schemas.android.com/apk/res/>
>>> android" android:layout_width="match_**parent"
>>> android:layout_height="match_**parent">
>>>         <TextView android:text="TextView A" android:id="@+id/
>>> textView1_a" android:layout_width="wrap_**content"
>>> android:layout_height="wrap_**content"></TextView>
>>>     </LinearLayout>
>>> ----
>>>
>>> When I click on the text view, the fragment should be removed, but
>>> nothing seems to happen. If I click again, the application crashes
>>> with the following error messages:
>>>
>>>     03-09 09:48:09.248: ERROR/AndroidRuntime(1222):
>>> java.lang.NullPointerException
>>>     03-09 09:48:09.248: ERROR/AndroidRuntime(1222):     at
>>> android.app.BackStackRecord.**remove(BackStackRecord.java:**365)
>>>     03-09 09:48:09.248: ERROR/AndroidRuntime(1222):     at
>>> test.fragments.**TestFragmentsActivity
>>> $1.onClick(**TestFragmentsActivity.java:28)
>>>
>>>
>>> Maybe it's not possible to remove fragments that were added using XML
>>> layouts?
>>>
>>> Thanks in advance.
>>
>>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Android Developers" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/android-developers/tWln4PFHFo0/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to