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.
Related
I have 3 different layouts in Activity, with a lot of fields. right now I use Tab layout, ViewPager2, Fragments in my activity for load these 3 Fragments that contain too many fields (that in the end all of the text in these fields must aggregate into one JSON Object or data class). I disabled on touch event for Tab Layout and swipe for ViewPager and use 2 buttons in bottom layout activity (for validating current fragment's fields). these 2 buttons used for next, previous, back to home, and submit. (Actually, I have 2 buttons and handle text and functionality for these buttons with View Pager position). everything works correctly unit now except this, I need to aggregate all fields into one JSON or data class in these different Fragments as one JSON Object or data class.
my question is:
Is there a better way to handle this scenario or this one is good?
(Considering that, in the submit button, I must get all value from fields into 3 different fragments and save into one data class then send it into another Fragment or Activity and save into SQLite database with room and my problem is here too. how I must handle it for clean code and good performance)
thanks for your help
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()
I have used Android Studio example with tabs and fragment, but I have some different idea. I need to automatically generate tabs and fragments, which will contain listview and will be populated using JSON.
I am successfully fetching data from JSON and placing them in one activity, but my intention is to use tabs which will serve as categories, so each time I click on different category it will show different news. My intention is that first time user clicks on tab/category, app should populate it with news, and next time he gets back it will not reload, it will show what is loaded before unless he wants to refresh it.
Refreshing category should be done by pulling down.
So, should I use one fragment as template, as all news will be presented the same way and populate it with data, or will I need to create fragment for each category?
If I will need to create different fragments for each, then in order to add new category I would need to update app version.
No need to create different fragment for each category. Just change the adapter content as you load data from server. But data for each category must be same ,means json object must have same keys in all categories. Otherwise use different fragments for each category of news.
Why dont you use pull to refresh on each tab fragment. And apply the condition, if pull to refresh then load new contents or refresh the data... or else display the old data as it is. Hope it helps you!
Scenario :
I need to create tabs/with fragment, and populate views inside each fragments dynamically. Also user can navigate inside each fragment depending on the server response.
Now what I am trying to do is setting same fragment for all tabs and passing different model data according to the tab content. Its working. When i need to show a details page inside a tab again I am showing same fragment with new data. but it makes issues (view mix up) on other tabs since the container is same.
Can anyone suggest a flow by using single fragment for any new views and i need to pop it out from backstack also.
I am developing an app where i am using tabwidget with 2 tab views. When the app is visible on screen, in first tab some data needs to be displayed in listview which i gets it from database. If the data is empty in listview by default second tab needs to be visible.
when the activity starts if the list is empty i want to start the other tab. if list is not empty the present tab needs to be visible..
The below image gives some more detailed information about my question.
Here as per the above images when app is visible to the user for first time, the data will be empty. so, i want to display AddGroup Tab to add groups. How is it possible to focus on Add Group Tab if list is empty in Groups Tab...
Setting the currently viewed tab can be done with
myTabHost.setCurrentTab(tabPos);
How you get to this TabHost object depends on where you are initialising the list: if it is done in the parent activity, (which extends TabActivity), you can use
getTabHost().setCurrentTab(tabPos);
If you need access to the TabHost from inside another activity (ie. when your tabs are activities) or View implementation (inside the ListView), add a method to your parent Activity that can be called by the classes in it, or objects that have a reference to it. Put this
public void switchTab(int tabPos){
getTabHost().setCurrentTab(tabPos);
}
in the parent activity, and then use something of the form
((MyParentTabActivity) MyChildTabActivity.this.getParent()).switchTab(1);
to access it, depending on where you want to switch it from.