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.
Related
I have one activity(MainActivity) and corresponding xml file. Xml file contains the toolbar on the top, then the sliding tabs then then viewpager.
I have 3 fragments(corresponding xml files) and 3 SlidingTabs. Tab 1 is connected with fragment 1 and 2 with 2 and 3 with 3.
If I am performing any operations on the views in the fragments, Do I need to write all the code in MainActivity or in the Fragment?
Do I have to return only the view from the fragment for that pager or all the codes for that page should also be there inside fragment?
For Ex:
If I am retrieving some data using contentresolver and populating the data on the listview in 1st fragment, Likewise, If I am doing some other operations and displaying the details in fragment 2 and 3, Do I need to write all the codes in the corresponding fragment itself or I have to write in MainActivity.
Can someone provide the answer to this or any link which will be useful.
When you are using Tabs with View pager, then MainActivity will just act as container and it holds Fragments.
So you can write respective code on respective fragments only. Any thing needed as common for all fragments then you can write in MainActivit. For Example Tool bar title changes, Option menu's ect..
Yes you have to return only the view from the fragment for that pager.And all the codes for that page should be inside fragment itself.
Only common codes or if you want to define any call back methods from the fragment, their implementations can we done in your activity.
Refer the below link where you can get an idea of your tabs implementation with few common material design controls.
https://github.com/chrisbanes/cheesesquare
im trying to implement an android aplication when your activity, cointains 3 or more 'main windows' like in the image -> 'A'. 'B'.'C'. so how is posible make when you slide you touch screen change from A, to B, for example, i was thinkin in a horizontal view, and inside of each item use a relative layout, but im not sure, its my first time with this kind of problem, thanks.
Try using android ViewPager. Each ImageView would be inside a Fragment that would reside inside your Activity. Check out this example
Use Tabbed Activity template when you want to make this type of Activity. ViewPager, Adapter and tab layout will be automatically implemented for you. Just make small changes in your Adapter according to your needs and use one Fragment for one tab and you can create as many tabs as you want in an Activity.
If you want i will post an example of an Adapter as i just implemented an Activity with 3 tabs.
To get your basics strong on ViewPager, tab layout and Fragment sections adapter read out this link.
I have fragemnt in which several buttons layaut and picture. In creating this fragment on top of the loaded data. in the lower part of the site for other fragments. One of the fragments contains a list. When I click on an item list, I need to update data on a fragment that contains this fragment. This hour I just create a new fragment the parent with the new parameters derived from the list. But I think it's not right. tell me how to update the fragment.ie I update the data and set to the desired form elements, but how to update the GUI itself
example may be easier
Using Interfaces for InterFragment communication should do the job for you.
https://www.youtube.com/watch?v=VyyGP_d0Ia8&index=8&list=PLonJJ3BVjZW4lMlpHgL7UNQSGMERcDzHo
Look into the below video, It might help you.
You should add interfaces to the fragment and implement them in your activity. Interfaces are good way to communicate between fragments. Take a look at here. In the implemented interface write code appropriately to change other fragments.
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.
Hi I am developing android application in which I am using one activity and two fragments. Consider same example which google explain like one list view and detail view. on click of list item we are rendering respective detail fragment.
So I learn how to do fragment transaction and i come up with two solutions. One which is standard way which google explain that make one interface and implement that interface into main activity. And do fragment transaction there inside main activity.
I tried with another way. when I click on list item inside click listener instead of calling interface I change fragment inside my list fragment only and its working fine.
So i want to know what is difference between those to methods. changing fragment from main activity and changing it from fragment only.
What kind of problem i will face if i implement with second method.i.e. changing from fragment only.
Need Help. Thank you.
What kind of problem i will face if i implement with second
method.i.e. changing from fragment only.
There isn't an actual problem, it's more of a design discussion. Using the second approach means you're making a very specific fragment, one that on a click on one of its rows will make a transaction with a specific fragment on a specific place of the holder activity. This would be a problem if you plan on reusing this fragment.
Suppose you have this ListFragment and you decided that it should be used in five other activities(with different data). Because it has a very precise action when clicking one of its rows, this fragment will always require the holder activity to have a specific container(where the transaction will be done) along the specific detail fragment with which it was initially used. The problem is that in each of those five activities you may want to use a different fragment when clicking a row of the ListFragment, this would require making changes to the class of the ListFragment.
Now suppose you have the same behavior with the interface approach. As the ListFragment doesn't know or care who handles that click event(as it passes it to whoever registers as the listener) you can simply put the ListFragment in the five activities with no problem(so no changes to it at all). In the interface method of the activity you could then implement the desired behavior with whatever fragment you want and in whatever container setup you want.