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
44
votes
1 answer

How to inflate view inside fragment

If I try to inflate a view within a fragment I am getting NULL.. For example: public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Here I will inflate my view using the…
Naruto
  • 9,476
  • 37
  • 118
  • 201
42
votes
3 answers

Hooking into fragment's lifecycle like Application.ActivityLifecycleCallbacks

In Android, if you have the Application context you can register an Application.ActivityLifecycleCallbacks instance that will be called everytime an Activity goes through one of its lifecycle callbacks. How can I accomplish the same for fragments? I…
Olinasc
  • 1,261
  • 1
  • 12
  • 20
42
votes
19 answers

Drag/Drop feature in Android studio not working

I'm new to android programming The drag/ and drop feature in android studio is not working. I can't drag anything to my phone. Right now my fragment is google map view and i want to add a search bar to the view. It just doesn't drag. When I try to…
anu
  • 703
  • 1
  • 10
  • 19
42
votes
9 answers

Prevent Fragment recovery in Android

We are using Fragments and we don't need them to be automatically recovered when the Activity is recreated. But Android every time when Activity::onCreate(Bundle savedInstanceState) -> super.onCreate(savedInstanceState) is called, restores Fragments…
goRGon
  • 4,402
  • 2
  • 43
  • 45
41
votes
12 answers

Fragment not receiving menu callbacks

I have a fragment class that extends Fragment and calls setHasOptionsMenu to participate in the menu. This class also implements onCreateOptionsMenu, onPrepareOptionsMenu and onOptionsItemSelected. public void onCreate(Bundle savedInstanceState) { …
aromero
  • 25,681
  • 6
  • 57
  • 79
41
votes
2 answers

Cannot resolve method 'show(android.support.v4.app.FragmentManager, java.lang.String)

For some reason when I try to show a Dialog I get an error from dialog.show(fm, DIALOG_DATE); saying Cannot resolve method 'show(android.support.v4.app.FragmentManager, java.lang.String)' Why can't it resolve the method?…
MasterProgrammer200
  • 1,021
  • 2
  • 17
  • 29
41
votes
5 answers

commitAllowingStateLoss() in fragment activities

my app uses fragment activities, it is in portrait mode only and there is no way to rotate the screen. Originally I was using the commit() method but now I plan to indiscriminately change these to commitAllowingStateLoss() for the fragment…
CQM
  • 42,592
  • 75
  • 224
  • 366
40
votes
1 answer

Does the Android ICS API have a native equivalent to ViewPager support lib?

I have searched a bit around for a pager for fragment , I develop on ICS API. I know about ViewPager and all the support libs for earlier version but i don't get why I should use a support library consider the fact that I use the lastest version of…
eephyne
  • 911
  • 9
  • 15
40
votes
4 answers

URL hash is persisting between redirects

For some reason, non IE browsers seem to persist a URL hash (if present) when a server-side redirect is sent (using the Location header). Example: // a simple redirect using Response.Redirect("http://www.yahoo.com"); Text.aspx If I…
chinabuffet
  • 5,278
  • 9
  • 40
  • 64
40
votes
5 answers

Fragment is transparent and shows Activity below

My Android application launches into BeginActivity which is a subclass of SherlockFragmentActivity and shows it's first view using: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); …
Darren
  • 10,182
  • 20
  • 95
  • 162
40
votes
13 answers

How to animate fragment removal

I want to animate the removal of fragment. I tried: getSupportFragmentManager().beginTransaction() .setCustomAnimations(R.anim.push_down_in, R.anim.push_up_out) .remove(myFragment) .commit(); but the fragment just disappears. I noticed…
hugoc
  • 777
  • 1
  • 6
  • 11
40
votes
3 answers

Can a ListView contain Fragments

As in, can the ELEMENTS of a ListView be Fragments. I know that you can assign a TextView XML to a ListView to change the way it looks, but can you add Fragments into a ListView. For instance: I have a Fragment. The XML for said Fragment contains…
user1449018
  • 663
  • 1
  • 7
  • 12
40
votes
2 answers

Passing objects in to Fragments

I've been working with lots of Fragments recently and have been using two distinct methods of passing in objects to the Fragments, but the only difference that I can see is that in the approach taken by FragmentOne below, the object you pass in must…
Martyn
  • 16,432
  • 24
  • 71
  • 104
38
votes
4 answers

Navigation Component prevent to recreate fragment on back press

I'm using the Jetpack Navigation Component in my project with a single activity and some fragments. I have a fragment with a list that fills from server side. I call getDataFromServer on the onViewCreated method then, when a user clicks on an item,…
38
votes
10 answers

How to pass and get value from fragment and activity

How to pass and get value from fragment and activity?
Best Best
  • 515
  • 2
  • 8
  • 17