[android-developers] Re: Honeycomb / Fragments: can't remove a fragment added in XML layout

2013-09-24 Thread 12169
if use want to remove the fragments then the best way to add it dynamically.
just create the fragment view in a seperate .xml file and add it to your 
manager using fragmentmanager that is associated with your activity.

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: 
> http://schemas.android.com/apk/res/ 
> android" 
> android:orientation="vertical" 
> android:layout_width="fill_parent" android:layout_height="fill_parent" 
> android:id="@+id/root" 
> > 
>  android:layout_width="fill_parent" 
> android:layout_height="wrap_content" 
> android:text="@string/hello" 
> /> 
>
>  android:id="@+id/fragment_a" 
> android:layout_width="fill_parent" 
> android:layout_height="wrap_content" 
> /> 
>  
>
> ** 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: 
> http://schemas.android.com/apk/res/ 
> android" android:layout_width="match_parent" 
> android:layout_height="match_parent"> 
>  android:layout_height="wrap_content"> 
>  
>  
>
> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
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 android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [android-developers] Re: Honeycomb / Fragments: can't remove a fragment added in XML layout

2013-09-24 Thread Clément Plantier
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 

> 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:
>>> >> xmlns:android="http://schemas.**android.com/apk/res/
>>> android"
>>> android:orientation="vertical"
>>> android:layout_width="fill_**parent" android:layout_height="fill_**parent"
>>>
>>> android:id="@+id/root"
>>> >
>>> >> android:layout_width="fill_**parent"
>>> android:layout_height="wrap_**content"
>>> android:text="@string/hello"
>>> />
>>>
>>> >> android:id="@+id/fragment_a"
>>> android:layout_width="fill_**parent"
>>> android:layout_height="wrap_**content"
>>> />
>>> 
>>>
>>> ** 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:
>>> >> xmlns:android="http://schemas.**android.com/apk/res/
>>> android" android:layout_width="match_**parent"
>>> android:layout_height="match_**parent">
>>> >> android:layout_height="wrap_**content">
>>> 
>>> 
>>>
>>> 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 android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> 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
> android-developers+unsubscr...@googlegroups.com.
> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
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

[android-developers] Re: Honeycomb / Fragments: can't remove a fragment added in XML layout

2013-09-24 Thread Piren
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: 
>> http://schemas.android.com/apk/res/ 
>> android" 
>> android:orientation="vertical" 
>> android:layout_width="fill_parent" android:layout_height="fill_parent" 
>> android:id="@+id/root" 
>> > 
>> > android:layout_width="fill_parent" 
>> android:layout_height="wrap_content" 
>> android:text="@string/hello" 
>> /> 
>>
>> > android:id="@+id/fragment_a" 
>> android:layout_width="fill_parent" 
>> android:layout_height="wrap_content" 
>> /> 
>>  
>>
>> ** 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: 
>> http://schemas.android.com/apk/res/ 
>> android" android:layout_width="match_parent" 
>> android:layout_height="match_parent"> 
>> > android:layout_height="wrap_content"> 
>>  
>>  
>>
>> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
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 android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[android-developers] Re: Honeycomb / Fragments: can't remove a fragment added in XML layout

2013-09-24 Thread Adarsh Pandey
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: 
> http://schemas.android.com/apk/res/ 
> android" 
> android:orientation="vertical" 
> android:layout_width="fill_parent" android:layout_height="fill_parent" 
> android:id="@+id/root" 
> > 
>  android:layout_width="fill_parent" 
> android:layout_height="wrap_content" 
> android:text="@string/hello" 
> /> 
>
>  android:id="@+id/fragment_a" 
> android:layout_width="fill_parent" 
> android:layout_height="wrap_content" 
> /> 
>  
>
> ** 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: 
> http://schemas.android.com/apk/res/ 
> android" android:layout_width="match_parent" 
> android:layout_height="match_parent"> 
>  android:layout_height="wrap_content"> 
>  
>  
>
> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
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 android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[android-developers] Re: Honeycomb / Fragments: can't remove a fragment added in XML layout

2011-03-09 Thread drasticp
I reproduced your issue. It seems the same for me.
FragmentTransaction.hide(Fragment) seems to work, but remove does not.
Also, the second attempt generates an exception as you described.

1up.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en