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!
Related
I am creating a shopping list app and was thinking of using BottomNavigationBar for it, so the three components of the bar will be List, Done, and Manage Categories or something.
Would this be a good way to go about my shopping list app? Would it work if I wanted it so if the user ticked of CheckBoxes in the List fragment, those items would move to the Done fragment? Or should I just use separate Activity?
You should use Activity with FrameLayout as a container for Fragments and BottomNavigationBar. Don't use multiple Activities in this case, it's not good practice.
What about checking boxes and sending information between fragments? You can save info to .txt file, some database (Room or Realm for example) or keep that information inside Activity and just send it to Fragment while creating them.
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.
This question is more my way of gauging a better understanding of the "Proper" way to handle this content flow instead of just "whatever works" or the "quickest" solution to code. Im looking for the best on performance and user experience.
The situation:
So my main activity handles my NavigationDrawer and is the basis of the app. The initial view that is loaded (navitem 0) is a Fragment which contains a RecyclerView(custom adapter, list item model, view holder). This list displays data pulled from an XML file and is returned as an Arraylist of Topic objects (each containing 3 strings and an array of Issue objects).
The array of Topic objects are used to populate the listitem w/ a title, desecription and image_name strings. (Not using the Issue array yet).
Here is where you come in ...
I know need to handle the click event on the Topic and display a new list (w/ different adapter) of the specific Issue object array for that Topic.
I'd like to know if its better to replace the current fragment w/ a new fragment for handling the Issue data. Or would it be better to launch a new activity to display the Issue list data.
Keep in mind, i want to ensure that navigation up will return the user to the previous view. ie. when clicking a Topic you should get the Issues for that topic. When going back, the TopicFragment should be displayed w/ its initial list.
If this is confusing you?
The core part of this question is needing to know the proper navigational way of displaying a List that when clicked needs to display another List specific to the parent object. Is fragment to fragment handled by callbacks in the MainActivity the best way, or is Intent'ing to another activity to handle the 2nd list better?
Whether you use a Fragment or an Activity to display the second list, it doesn't matter from a performance standpoint. If I were you, I'd use an Activity: it is always better to use a Fragment only in situations that require the explicit use of Fragments (such as a FragmentTabHost or a ViewPager).
But I do have another suggestion for you. Instead of going to another list, why not display your Issue objects as the child items of an ExpandableListView, and the Topic objects as the parent items ? Then when the user clicks on an Issue child item, go to the detail page containing details of that Issue object. To me, the List->Detail pattern is a far more familiar idiom than a List->List->Detail flow. Its what ExpandableListView was made for.
I have a hierarchical data structure. As an example, lets consider my data television shows. Each show has multiple seasons and each season has several episodes. I want to have a list that displays all shows. When a show is clicked the list will then display all seasons for that show and when a season is clicked the list will show all episodes for that season.
OK so with that out of the way, currently I have ONE Activity that implements a Loader through LoaderCallbacks. This loader returns a full hierarchy of data (AKA all shows with all seasons with all episodes). I then use a different ArrayAdapter depending on the level of data I'm on.
Is this the 'right' way to handle this kind of data? Should I instead have a loader and activity and adapter for each level of the data?
Sorry if this is confusing, thank you in advance for your insight.
There really is no right or wrong here. I would go for one activity and adapter per set of data. This will make your activities less complex and make them decoupled from each other. In your case I would have:
ShowActivity+ShowAdapter
SeasonActivity+SeasonAdapter
EpisodeActivity+EpisodeAdapter
Your data model (with Shows, Seasons and Episodes) should be made accessible to the activities and used to initialize each activity and adapter with the correct data.
Once a show has been selected I'd pass on the id of the show to the next activity through the intent bundle, pick up the show id in the SeasonActivity, fetch the relevant seasons from the data model and display them. The same goes for the transition from season to episode.
Using the approach of one activity per list you'll also get nice transitions between activities and don't have to worry about dealing with the back button to navigate up through your hierarchy.
Good day,
I make my test application in Android and find some difficult moments to do by myself.
I have two Tab Fragments and Host Activity (that creates two tab fragments) with Action Bar (actionbarsherlock). One Fragment allows to add some information about product and persist it into SQLite. Other Fragment has a listview that displays all the products from database.
The problem is that in the first tab I persist data in different thread with 5 second delay, so you click "Add Product to Database" button and after 5 seconds it will be added. But right after clicking I can switch to another tab with listview and the situation is as follows: data from the first fragment is not persisted yet because of delay, but after it is persisted, nothing changes in listview - the listview doesn't know about changes. I need listview updated authomatically when it notices there are changes in database. How can I do this? I use ArrayAdapter to populate data into listview.
I think you need necessary use broadcast receiver, and in it call method refreshDrawableState() for you list. Respectively receiver is your activity.