I have a tablayout in my project with each having it's own fragments now the tab layout is working fine. My problem is how can I access the elements like edit text values and other from the fragments I'm totally confused of that. Kindly help me in this issue I browsed a lot videos in YouTube but every video shows how to create a fragment and there aren't showing what I need.enter image description here
You must firstly make the the MainActivity's component reference variable public.
e.g
public EditBox mEditBox
To get this variable in your fragments, simply type:
((MainActivity)getActivity()).mEditBox
So to get the EditBoxes text value you would type
String value = ((MainActivity)getActivity()).mEditBox.getText().ToString()
Related
I have an android app that takes data from JSON and creates as many tabs as indicated in the JSON along with relevant content.
On running the app, all my tabs show the contents but one of the tabs shows NO content.
I have implemented the tabs using fragment.
In the tab with no content, the content to be fetched from JSON are of spinner type. When I put a content of edittext type as the first content, then all the contents get displayed
Can you please tell me the possible reason?
if everything has been created dynamically then check that on that particular categoryid of fragment data is present or not(on postman), if data is coming from that categoryid of that fragment. then there must be mistake in any KEY name in model class.
I am using tab layout and want to update the value of a variable of 1st tab from 2nd and 3rd tab.
is it possible to do what i asked about .
i have searched many things but couldn't get accurate or convincing answer.
please help me.
Thanks.
I am new to Android programming. I started building an app using YouTube tutorials but I am a little bit confused and facing a problem. Should I use fragments or activity in my sliding tab? I am working on an Android project of employee attendance and payroll so I am thinking of using a slide tab (something like the screenshot below). The 1st tab may contain a form to add an employee and after adding it, will display information in list view and the other may contain salary. Should I try fragment or activity for my tabs?
A fragment is always located in an activity.
So you wil always need an Activity and then add the fragment to the activity.
if you say you want to slide?
you probably mean a viewpager, that can have n fragments. the viewpager needs a special viewpageradapter. where you define how many fragments you want. and at which index what fragment needs to be shown
Well,I have been trying to figure it out how to add dynamic tabs from json field from server and somehow I was able to show it.I manually defined two tabs which has their own .java files for that.Those dynamic tabs are showing right after those two tabs but I don't know how to add fragment to that dynamic tab.I am bit confused how to put this but just please try to go through.
Deeply Appreciated.Thanks
Use a (TabLayout + ViewPager) combo. Then with the help of JSON parsing add the number of tabs you require on calling the activity and then call the fragment content to be refreshed with onTabSelectedListener for best performance stability. It works like a charm.
The best way to dynamically manage tab, is by using ViewPager and Adapter. If you want to know, how that ViewPager with adapter should look like, you can create new Tabbed Activity in Android Studio.
Right-click on your main package -> New -> Activity -> TabbedActivity
Android Studio will create sample Activity with ViewPager and adapter. You can analyze that code and modify according to your own preferences.
Afternoon guys, my problem is:
I have a main tab that contain a 'Search' button, when it's pressed it should load data from the database (which is OK) and apply it to all the tabs (here's the problem)
How an i supposed to do this, is it possible?
If it's not possible, is there any way to pass info trought tabs? Like the customer ID so i could search his info whenever the tab changes?
Thx
Ye is possible. Save the content in one global variable and use it in the next tab. In your case if it is string save declare one private/public string variable outside the tabs, when is needed assign data to the string, and use it in the same in the next tabs or whatever you want.