Questions tagged [fragment]

**DO NOT USE**: fragment is an ambiguous tag, used to refer to numerous technologies. Prefer less ambiguous tags. For Android Fragments, use [android-fragments]. For URL fragments, use [url-fragment]

'fragment' Tag Disambiguation

8161 questions
38
votes
6 answers

SavedInstanceState is always null in fragment

I have a fragment attached to the activity using XML (and setContentView() in activity). A have a problem because I have very dynamic views in my fragment, so when orientation changes I must restore all states of views. I have problem because I'm…
TommyNecessary
  • 1,377
  • 1
  • 13
  • 19
37
votes
2 answers

Custom attributes in Android fragments

I'd like to define custom attributes in Android fragment using XML (without using bundle additional parameters) like declare-styleable in custom controls. But there are no constructors with AttrSet parameters, so is it possible? Can i just override…
Anton
  • 1,903
  • 3
  • 16
  • 18
37
votes
1 answer

When to use the attach and detach methods of FragmentTransaction

I just went through the documentation of the attach() and detach() methods of FragmentTransaction: attach(): Re-attach a fragment after it had previously been detached from the UI with detach(Fragment). This causes its view hierarchy to be…
GingerJim
  • 3,737
  • 6
  • 26
  • 36
36
votes
2 answers

Adding Tab inside Fragment In Android?

I am trying to add a TabHost inside a Fragment. The code is given below. Here inside the Fragment. I am trying to add TabHost to show two Tabs: package com.nordicsoft.dilosysNewVersion; import android.app.Fragment; import…
NRahman
  • 2,717
  • 5
  • 24
  • 29
36
votes
3 answers

Call parent's activity from a fragment

If I'm inside a Fragment how can I call a parent's activity?
user1746708
  • 691
  • 1
  • 8
  • 16
35
votes
3 answers

Fragment methods: attach(), detach(), remove(), replace(), popBackStack()

I am very confused between these functions and their purposes. What I have observed that using replace() replaces the existing fragment with a new one. We can use addToBackStack(null) to put that fragment in back stack so we can go back to the…
Vikram Gupta
  • 6,496
  • 5
  • 34
  • 47
35
votes
5 answers

Can't get Action Bar in fragment class

I have an activity with three fragment classes inside it. I get an error when trying to change the action bar title from inside of them. If I try to make the classes just public and not public static I get an error when I try to start that class. It…
SweSnow
  • 17,504
  • 10
  • 36
  • 49
35
votes
3 answers

ViewPager FragmentPagerAdapter Nullpointer

I got this error by using the ViewPager in the Android Support package. from the Horizontal View Swiping with ViewPager Tutorial 06-19 13:07:25.950: E/AndroidRuntime(16382): FATAL EXCEPTION: main 06-19 13:07:25.950: E/AndroidRuntime(16382):…
passsy
  • 5,162
  • 4
  • 39
  • 65
34
votes
2 answers

Integrating youtube to fragment

My Activity extends another activity and consists of navigation drawer where each item opens a new fragment.I want to integrate Youtube to one of the fragment..Previously i used YouTubePlayerView to integrate Youtube to activity but here it is…
Android Developer
  • 9,157
  • 18
  • 82
  • 139
34
votes
6 answers

Best practice to handle orientation change: Android

I was going through various practices to handle orientation change with threads and AsyncTask. I came across following solutions: Attach-detach model : Attaching and detaching activity to threads and AsyncTask while preserving their instance.…
Gaurav Arora
  • 17,124
  • 5
  • 33
  • 44
34
votes
1 answer

How does `onViewStateRestored` from Fragments work?

I am really confused with the internal state of a Fragment. I have an Activity holding only one Fragment at once and replaces it, if another Fragment should get shown. From the docs onSaveInstanceState is called ONLY if the Activitys…
Rafael T
  • 15,401
  • 15
  • 83
  • 144
34
votes
6 answers

Fragment activity catch onKeyDown and use in fragment

I have Fragment activity with pager: List fragments = new Vector(); fragments.add(Fragment.instantiate(this, PastEventListFragment.class.getName(),bundle)); fragments.add(Fragment.instantiate(this,…
FlorinD
  • 481
  • 2
  • 8
  • 25
34
votes
5 answers

Android: Change Background Color of Fragment

I tried changing the background color of a fragment, but a small problem occurred. public class MainActivity extends FragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); …
Brandon Ling
  • 3,841
  • 6
  • 34
  • 49
33
votes
8 answers

Is there something like React.Fragment in Vue?

In React I can do something like this: // parent component export default (){ return (
1
5
); } // child component export default (){ return ( …
RickyChan
  • 469
  • 1
  • 4
  • 9
33
votes
1 answer

Prevent Proguard from removing empty constructor of fragment

You know, all subclasses of Fragment must include a public empty constructor but when using proguard these constructors will be removed. I have specified below commands but empty constructor still be removed. Can anyone help me to keep empty…
Wayne
  • 6,361
  • 10
  • 46
  • 69