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
20
votes
8 answers

Get value from Bottom Sheet Dialog Fragment

I'm starting bottomSheetDialogFragment from a fragment A. I want to select the date from that bottomSheetDialogFragment then set it in the fragment A. The select date is already done, I just want to get it in the fragment A to set it in some…
Abdulrahman
  • 301
  • 1
  • 3
  • 12
20
votes
3 answers

Passing a listener to a custom Fragment in Android

I'm creating a view pager in my app and using a class that extends Fragment on it. When I create an instance I can pass all the elements (an image, text, etc) and store it with the Bundle to use it in the onCreate. But I can't store a listener for…
Jaime Alcántara Arnela
  • 2,062
  • 5
  • 25
  • 56
20
votes
4 answers

How to use method onNewIntent(Intent intent) inside a Fragment?

I'm trying to use NFC Hardware from my device. But, the problem is that when I register the Activity to receive the Intent: PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this,…
20
votes
2 answers

Fragment isAdded() returns false on an already added Fragment

I have this neat function: private void addMapFragment(){ if(!mapFragment.isAdded()){ FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.add(R.id.mapContainer, mapFragment); ft.commit(); } } I'm…
Lumbi
  • 688
  • 2
  • 8
  • 17
20
votes
7 answers

ActionBar (Support) with Fragment (support)

I need to use a combination of action bar and fragments in one of my android applications that targets Gingerbread too. So I have used the action bar from the v7 support library and fragments from the v4 support library and extend my class with…
Anirudh
  • 2,080
  • 5
  • 21
  • 34
20
votes
5 answers

using alt in sequence diagrams for starUML

i am not able to discover how to use the alt/combined fragment correctly in starUML,as in there is no way that i am able to provide the condition after the alt fragment appears.can any1 just list down the procedure as to how to do it or a link to…
arinjita paul
  • 201
  • 1
  • 2
  • 4
20
votes
4 answers

Implementing onKeyPreIme(int keyCode, KeyEvent event) in Fragment

I cannot figure how to implement onKeyPreIme(int keyCode, KeyEvent event) in a Fragment. @Override public boolean onKeyPreIme(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() ==…
Max
  • 572
  • 2
  • 6
  • 23
19
votes
2 answers

Android fragments vs compound controls

Why should Android 3.0 fragments be used instead of compound controls? One can create a View inheritor or compound control once and use it everywhere. I've read http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html but did not…
Anton
  • 1,903
  • 3
  • 16
  • 18
19
votes
7 answers

the status bar changes it's color to black inside fullscreen dialog fragment android

I'm using dialog fragment. The problem is that the status bar color is changed to black. How to change it to some other color? It's strange cause inside fragment, activity it works fine. Its only black inside DialogFragment @Override …
19
votes
2 answers

why we can call getActivity() in onCreateView which run before onActivityCreated?

I really get confused with Fragment lifecycle, especially for the time to call getActivity(). Sometimes you cannot get Activity by getActivity(). And it always caused some puzzling bugs. Thank you for anyone can solve the puzzle.
CodeAlien
  • 766
  • 2
  • 7
  • 15
19
votes
1 answer

How to put viewpager inside fragment in android?

I've an activity and I can show some fragments on framelayout on this activity. I would like to put a viewpager made up of fragments inside a fragment instead of a FragmentActivity. How can this be done?
Sayed
  • 255
  • 1
  • 3
  • 14
19
votes
5 answers

How can I declare a Fragment as hidden in an XML layout

My activity declares all of its GUI fragments in a single XML layout. It only needs to display a few of the fragments at launch time; the rest get shown as the user interacts with the app. A portion of the layout is as follows:
Jay Lieske
  • 4,788
  • 3
  • 30
  • 41
19
votes
5 answers

How to clear arguments in Fragment?

I have an AudioPlayerFragment to which I pass some url with setArguments(). If I have an url key in the getArguments() of my instance of AudioPlayerFragment, I start a service that plays the audio stream. If there was already a stream playing, I…
jul
  • 36,404
  • 64
  • 191
  • 318
19
votes
1 answer

onCreateView() in Fragment is not called immediately, even after FragmentManager.executePendingTransactions()

I read that if we need to create fragment immediately, we have to call executePendingTransactions() method on FragmentManager. Well, that's what I'm trying to do. Like this: @Override protected void onCreate(Bundle savedInstanceState) { …
Piotr Chojnacki
  • 6,837
  • 5
  • 34
  • 65
19
votes
4 answers

Fragments overlapping each other

I have an action bar with 3 tabs, each tab opens a fragment. The third tab, "Catalog", has a list: When I click on an item it opens another fragment, which is not part of the action bar: public void onClick(View v) { switch (v.getId()) { …
Igal
  • 5,833
  • 20
  • 74
  • 132