Questions tagged [android-fragments]

12390 questions
1

votes
3

answer
469

Views

How to open URL from Fragment TextView?

I have an activity with multiple tabs and each tab consists of a fragment with some text inside. I would like to have a text with 'Read More' which is a link to an URL. Without having the link, everything works fine, but when I try to implement it, I get E/UncaughtException: java.lang.NullPointerEx...
CuriousPaul
1

votes
0

answer
16

Views

Why can't I override Fragment.onAttach(Context context)?

A member on my team generated stub fragments in Android Studio, and onAttach(Context context) was automatically generated. However, the compiler reports the following errors in my code, shown below: import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; imp...
bko
1

votes
0

answer
16

Views

I have a problem saving the date I picked using date picker fragment to my database

I have this problem saving the date I picked in a string variable in my database I have already tried saving it formatted with a forward slash and not formatted as a whole number but none of these worked out for me I have it in a RecyclerView like a list of things that when you click on one of the...
Hitham
0

votes
0

answer
6

Views

ViewPager Fragments are not initialized immediately

I have a ViewPager with an adapter of FragmentStatePagerAdapter. For the sake of simplicity I have 2 Fragments within my ViewPager. class MyPagerAdapter(fragmentManager: FragmentManager): FragmentStatePagerAdapter(fragmentManager) { var firstFragment: SampleFragment? = null var secondFragment: Samp...
musooff
1

votes
3

answer
1.6k

Views

How to change View of the Activity from within the ViewPager's Fragment?

I need to change a TextView's text that is placed in the layout of my FragmentActivity that has a ViewPager and a ViewPagerAdapter. Basically I have created an action bar in my application that presents the name of the current visible Fragment. So I need this TextView to be changed on each change of...
Emil Adz
1

votes
2

answer
5k

Views

How to launch activity from Navigation Drawer?

So I've searched allot about navigation drawers here, and when I was pointed to a tutorial from an answer in another persons question. I did so. I successfully managed to create and style the nav drawer to my liking. But now I've been searching tirelessly on how I can launcher activities from the n...
Robin
0

votes
0

answer
7

Views

How to force Margin-left (marginStart) to image in a fragment?

I have a statistic/history screen in my app, which shows the last 7 days history of user's activity. I've been using 7 fragments on the same screen to represent each day (7 days ago, 6 days ago....). On each fragment there is an image which should be changed, regarding the condition. The problem is...
Elie Dev
-1

votes
0

answer
16

Views

Starting a new activity from a fragment

I'm looking to start a new activity directly from a specific fragment. Currently, the error I'm getting is that onClickListener() can't be resolved. I had a lot of issues doing through inside onCreateView(), so now I'm attempting to do it inside onViewCreated(). public class TermsFragment extends F...
Matt Joslen
1

votes
2

answer
2.8k

Views

Click On An Item In RecyclerView Contained In A Fragment To Open New Activity With Passed Data

I have a MainActivity and Three Fragments with recyclerViews inside the three fragments, the recyclerview contain two textviews, i want the user to click on the recyclerview and the text in should be passed on to the new activity, i am a little bit new so i would appreciate it if you can give me det...
winfred adrah
1

votes
4

answer
53

Views

What am I doing wrong with the getActivity method?

I cannot figure out for the life of me what the getActivity method does. I'm relatively new to programming android and I'm trying to give my app it's own small amount of storage. To do that I'm using SharedPreferences. Usually I wouldn't be copying 'word for word' what's on Android Developers but, I...
Noah Baxley
1

votes
2

answer
33

Views

Load a fragment inside another fragment in Android [duplicate]

This question already has an answer here: Fragment Inside Fragment 13 answers Im trying to implement Autocomplete from Google Maps SDK. I have found a guide where it uses a Fragment to show the bar where you can search for an address with autofill functionality. My problem now comes when trying to...
Patrick Vibild
1

votes
0

answer
17

Views

I have one button in fragment and textbox in main activity. now if i press button in fragment some message will print in textbox . How to do it?

I have one Button in fragment and Textbox in main activity. Now if I will press button from fragment, some message will print in Textbox. How to do it? public class MessageFragment extends Fragment implements View.OnClickListener{ public buttonPress press; public interface buttonPress { void getText...
Monil Gandhi
1

votes
0

answer
41

Views

Dynamically adding custom Views to TableLayout

I'm trying to dynamically add custom Views to TableLayout. Adding things like TextView works but when I'm trying to inflate my own I see a blank screen. I saw similar questions but none of them had was any helpful. I have a layout which is inflated into a Fragment: And then I am dynamically adding r...
kaichi
1

votes
1

answer
303

Views

Fetch data using volley and display in Google Maps

This is my first time working with Google Maps in android. I was able to create a map displaying one marker. That was a good start for me. However, I would like to display multiple markers. To do these, I am fetching the locations from the database using volley. However, I am experiencing one proble...
1

votes
1

answer
23

Views

Views in Relativelayout inside a Fragment have extra spaces

I'm working on my landscape layout which is a RelativeLayout with a CardView, two ImageViews and a simple TextView. On the preview in Android Studio it looks exactly like what I want but if I test it on my real device it looks strange because there are always extra spaces. This is the preview in And...
Deno Agüero
1

votes
1

answer
67

Views

Use both v4 Fragment and native Fragment in One ViewPager

Is there a way to use both v4 fragment and native fragment in same ViewPager? Any ideas helps.Thank you!
kent218
1

votes
0

answer
27

Views

Activity always on top [Check out bar]

I have an shopping app and when a customer adds an Item to the shopping cart a bar should appear in the bottom part of the screen, providing the customer to checkout or edit the cart. This bar should stay in the bottom of the screen until the customer reset the cart or checkout, and it may display r...
Joel Broström
1

votes
0

answer
101

Views

How to add Fragment from BaseAdapter

I'm developing an English-Japanese learning app, where it has a stack of cards where users can swipe through, and on each current card, the user can touch the card to flip to the other side of a card, which show the meaning of the word. For the swipe function, I'm using a library SwipeFlingAdapterVi...
Quan Nguyen
1

votes
0

answer
19

Views

Fragments that can be swiped in 4 directions

So basically I want to create an app that when I swipe left it shows a fragment and so as up down and right. Here is the code I have so far @Override public Fragment getItem(int position) { switch (position){ case 0: return ChatFragment.create(); case 1: return EmptyFragment.create(); case 2: return...
KristoferH
1

votes
0

answer
121

Views

java.lang.IllegalStateException getString in Retrofit2 Callback

I'm getting this error in a Retrofit2 onResponse java.lang.IllegalStateException while trying to get the SharePreferences to save some values in a Fragment. MyApi myApi = retrofit.create(myApi.class); Call myApiCall = myApi.getThoseValues('Some dummy parameters'); myApiCall.enqueue(new Callback() {...
UrielUVD
1

votes
2

answer
242

Views

Calling fragment method from Asynctask PostExecute

I need help on how to call a method that is in a fragment from a class AsyncTask. I've been looking to similar questions, I've tried some things and it has not worked for me. The problem: The AsyncTask class downloads an XML and saves some tags that interest me. Next in the method onPostExecute I ha...
Splanas00
1

votes
0

answer
44

Views

Fragment View's state is broken by FragmentManager

I wanted to retain views through fragment replace operation and noticed a strange bug: After fragment's View is destroyed through replace operation, it still has a parent, however, the parent doesn't have the view among its children. private View view; @Override public View onCreateView(...) { if (...
Bolein95
1

votes
0

answer
45

Views

Dyanamic tabs creation with dynamic view pager fragments

I want to create a dynamic swipe able tab layout. I am able to create dynamic number of tabs, but i am not able to figure out how to create fragments dynamically for corresponding tab and also views inside each fragment.
Er Vishnu Sharma
1

votes
1

answer
219

Views

Getting song image very slow (MediaMetadataRetriever)

I am working on media player application i am getting song image using MediaMetadataRetriever and i am getting image and and i set using Glide but image takes about 7-9 sec to load that is very very slow. i also try using BitmapFactory but that also same time. so there is any faster way that can i...
Jigar Fumakiya
1

votes
1

answer
57

Views

Bottom nav with fragments FATAL EXCEPTION sdk<22

I'm trying to setup a BottomNavigation displaying 3 Fragments. The problem is that app fully works on Android 5.0, but throwing ERROR on Android 6.0 and higher... -- compileSdkVersion 26 -- minSdkVersion 21 -- targetSdkVersion 26 -- To be sure I've been using the example to build this app, and aft...
Brachu
1

votes
2

answer
246

Views

How to pass array bundle from fragment to fragment

I have added my API response data into arraylist and tried to pass that arraylist to next fragment.but in second fragment i'm getting null result.below is my code. First fragment ArrayList productList; Bundle bundleProduct; public void getProduct(id){ productList = new ArrayList(); bundleProduct = n...
user8164155
1

votes
0

answer
37

Views

Call a method of the Main Activity from a map fragment doesn't works

I'm making an app in Android that connects to a REST server, from where it returns the coordenates to generate markers in a Map Fragment. I have two types of markers, those that are from an activity and those that are from a commentary. The comment's markers are blue and the activity's are red. I ha...
Asez97
1

votes
2

answer
293

Views

Stop/start mediaplayer from another activity

i'm trying to play stream radio using Mediaplayer with MP1 as variable of Mediaplayer i want to play it in all Fragments app,expect one activity (ActivityOne) which is contains another Mediaplayer MP2 to play,so i want to stop MP1 when i'm in (ActivityOne) activity, and play MP2 , and when i return...
iFi
1

votes
0

answer
36

Views

CollapsingToolbar doesnt work

I have a main activity ​​with a hiding toolbar, and a tabLayout. In the tabs - fragments. In one of the fragments, there is also a hiding toolbar, and a recyclerView. How to make, that at a scroll at first the toolbar in a activity collapses, then in the fragment? Now, if I scrolling, collapsin...
Tigran
1

votes
1

answer
261

Views

FragmentStatePagerAdapter view pager fragments not showing after activity recreate

When my Activity gets recreated via orientation change or if 'Don't keep activities' is turned on in developer settings, my ViewPager that has FragmentStatePagerAdapter doesn't recreate fragments. this is activity onCreate method: @Override protected void onCreate(@Nullable Bundle savedInstanceStat...
choki1708
1

votes
1

answer
47

Views

Where to add code for onBackPressed() for Fragements

i`m having an app with only one activity but 3 fragments. Now i found a way (Youtube Video) to stop the app to exit complete after hitting the back button on my phone. boolean twice = false; @Override public void onBackPressed() { Log.d(TAG, 'click'); if(twice == true){ Intent intent = new Intent(In...
Bindl
1

votes
1

answer
255

Views

Switching to first tab in tabbed activity not working properly in android

So I have a weird problem. Basically I have a Main activity with four buttons, each button opens a different tab (there is 4 tabs). Now If I click 4th button I go to the 4th fragment but then if I try clicking on the first tab in tabbed activity it doesn't do anything. So I can't go to the first tab...
Paulina Maz
1

votes
0

answer
433

Views

Take focus away from tabs in ViewPager/TabLayout

I am using ViewPager/TabLayout on Android TV, and I have 2 questions. 1) Currently, if I press DPAD_UP, the focus goes to the tabs, but the page does not actually change to the one corresponding to the focused tab until DPAD_CENTER is pressed. So, there is a difference between focused (shown as a g...
kent218
1

votes
0

answer
159

Views

Hide/show fragments in single ViewPager window

How can I hide SearchFragment and display ChatFragment, without remove() in ViewPager? I had no issues with creating new instance everytime, but I don't want onDestroy() to have place, since i will be switching these 2 views very frequently. I want to create them once and have the ability to show/hi...
ashaneen
1

votes
2

answer
40

Views

inter fragment communication onclick textview is null but in oncreate view textview is there

Hi there, I try to sent data from one fragment to another fragment by implementing an interface. The interface Communicator implements two functions one of them is sendToBill(itemType, itemPrice). When the add button is clicked in the in the CategoryFragment class i want the the price of the item to...
mvz
1

votes
1

answer
118

Views

Fix blink in Fragments during addSharedElement() transition

I use the next code in Fragment A: fragmentManager!! .beginTransaction() .addSharedElement(viewHolder.characterImage, ViewCompat.getTransitionName(viewHolder.characterImage)) .addToBackStack(TAG) .replace(R.id.fragmentContent, CharacterFragment.newInstance(url, viewHolder.characterName.text.toString...
Ruslan Leshchenko
1

votes
1

answer
42

Views

Music service Not Working with Album songs

I developing music app.so i create Music service that play in song background so that work perfectly good in when i play song. But my question is we need different different service for all. so when i use music Service for album for playing album song that not working. i don'i know what to do tha...
Jigar Fumakiya
1

votes
1

answer
137

Views

Android linearLayoutManager.setStackFromEnd() not working for chat show last element

I'm working on a chat application. Now, while fetching messages from the back-end for the first time, i want my Linear Layout pointer to move to the last message in the list, so that the user always sees the latest messages on opening the chat fragment. This is my code: LinearLayoutManager linearLa...
H. Goyal
1

votes
3

answer
189

Views

Find the width of a view inside of a fragment

I want to find the width of a view inside of a fragment and I've written the following code class ExampleFragment : Fragment() { var team1_value = 0 override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { // Inflate the layout for this fragme...
unknown1
1

votes
1

answer
225

Views

Why is the RecyclerView adapter not updating correctly (only the first time) despite getting the correct data?

This is very strange. For some reason, despite getting the correct data from the REST call, the adapter is not updated correctly in the RecyclerView. Here are the two methods: public Observable getTopicsByCreator(GetTopicsByCreatorRequest request) { return getApi() .getTopics(request) .subscribeOn(S...
bycfly

View additional questions