Get data from three tabbed activity - android

I am using tabbed activity and have three layouts and I wonder how its done when I want to get the data from all the tabbed activities are not in the view.
They all have different layouts so I cant use "findViewById" to retrive the data thats not in the view.
I thought I was smart and maybe i chould use "findViewById(android.R.id.content)".

Related

Choosing between activity and fragments (showing map)

I have three screens looks exactly same with different set of data loaded on them.
What design pattern shall i use for it.
Tab1,2,3 also loads different data (Loading from database).
One activity and different fragments loading data accordingly.
Three activities using same layout.
Plane simple three activities. (Or more for tabs too - not sure)
I'm not really sure what your data is, but is there a reason you can't just cache the data in say, a content provider? Then you could use one activity, one fragment and just have listeners to load different data from the provider.

should i use a Fragment or an Activity for an ever present View in my Android App?

im developing an application with multiple screens using activities and fragments. The principle behind my decisions to use one or the other are based on the interaction in the application.
I have come to the conclusion that you should use an activity whenever major UI elements remain present after an event has occurred that forces the views inside the UI to change (An example of this can be a tabhost nested in the toolbar styled as the Google Play store android App with multiple fragments as childs. Another example is fragments representing the different rows or clickable elements on a navigation drawer).
So right now im presented with the dilemma of choosing once again between the two (fragment or activity) for a UI element that is going to be present across my whole application. Its triggered by a floating action button that launches a creation tool for an element inside my application and i needed to be accesible across all of my apps screens.
So to sum things up, what i need to know if its better to use a fragment or an activity for an element that is ever present across my whole application.
Thanks in advance
Use Fragments or a compound Views. But both in the right way.
Fragments are thought for reusable combinations of views. Compound Views are Layouts containing views. They are the right way if you want to create views from more primitive views, for example a View containing TextView and a increment- and decrement-button.
Fragments are more Activity-like. They have a real lifecycle. Your description looks like you want to create acitivity-parts. And thats exactly what fragments do.
A Fragment represents a behavior or a portion of user interface in an
Activity. You can combine multiple fragments in a single activity to
build a multi-pane UI and reuse a fragment in multiple activities.
Taken from Android SDK Documentation: Fragments.

Clarification on the structure of my app

Some background info first. I require my app to show a feed of posts, implemented as cards. The data within the posts/cards is retrieved from my site's REST API. My app has 3 different tabs, each containing a different feed of posts/cards (but still the same layout).
Currently, I have an activity_main and the 3 fragments made for each tab (fragment_1, fragment_2, fragment_3). To my understanding, a Fragment is a layout that can be re-used on different Activities. Is this correct?
Additionally, where should I implement the layout/design for the cards? Should it be directly within the separate Fragments (even though the layout of the cards will be the same across all 3 tabs)?
After implementing the card layout, how would I populate the cards given the requested REST API json data? In other words, how would I loop through each result and insert the data into the card and display it on the screen?
Sorry for the noob questions.
Currently, I have an activity_main and the 3 fragments made for each
tab (fragment_1, fragment_2, fragment_3). To my understanding, a
Fragment is a layout that can be re-used on different Activities. Is
this correct?
Yes.
Additionally, where should I implement the layout/design for the
cards? Should it be directly within the separate Fragments (even
though the layout of the cards will be the same across all 3 tabs)?
Have a single fragment. Create 3 instances of this fragment and inflate the same layout/design if the layout of the cards will be the same across all 3 tabs.
After implementing the card layout, how would I populate the cards
given the requested REST API json data? In other words, how would I
loop through each result and insert the data into the card and display
it on the screen?
Pass a unique identifier that identifies the feeds (for this fragment) to the fragment as a bundle when you create a new instance and set them as the fragments argument. You can then retrieve this information to retrieve data relevant for this fragment.
To display the data, use a ListView/RecyclerView along with a suitable adapter to connect your data to your view.
I hope this answers your question.
OK. Lets try this. Yes, you are right, Fragments are basically layouts that can be used in different Activities. As it says on Android Developers site:
A Fragment represents a behavior or a portion of user interface in an
Activity. You can combine multiple fragments in a single activity to
build a multi-pane UI and reuse a fragment in multiple activities.
Having that said, since it is the same layout for all three tabs, you can use only one Fragment and populate it with different data. So if you want to change anything, you would do it only within that one fragment.
For the cards I am guessing that you will be using a custom ListView adapter. And that you should (must) implement outside the Fragments.
And regarding the last question, there are many libraries that make consuming ReST webservices much easier. For example Retrofit.

use of multiple fragments inside a fragment in android

I have a requirement in my application. my application has 6 fragments in a Navigation drawer each fragment represents single item in navigation drawer list.
But in one of the fragment i need to implement a form which will be spread across 5 views one at a time, can any one suggest me how to approach this in android.
Initially i thought of doing this using ViewPager , but i dont need horizontal swiping but need to go to next screen when clicked on a button.
Kindly advice me how to approach this.
Thanks & Regards.
Nagendra
You can create main fragment and sub-fragments. Inside the main fragment, show the sub-fragments by replacing them, store the data by creating an entity object here and pass it to the sub-fragments. Inside sub-fragments, pass the data to the main fragment entity using listeners.

Android : Which method is better for navigational Listview (fragment or Listactivity)

I am a novice in developing android app ! I am working with Android Studio!
Want to implement a tab-panel in which some of the tabs (as this) will contain listview to hold some data or image from a json Webservice! While the data comes from internet connectivity so there is performance is a issue for me!
I have got two types of way to implement tabs in android! One is listactivity & other is fragment! I just want to know which of these two way is efficient for implementing tabs on android??
A listActivity is an activity, and you cannot bind a different activity to each tab-panel, but you can put a different fragment on each panel (or use a single container, and just replace the fragments there with transactions).
You can also use another fragment to display the tab-interface at the top, which remains constant as the contents below changes. Something you couldn't do if you were switching activities.

Categories

Resources