Android swipe between fragments - java

In my Android APP I have this ListView where I wish that each item is divided in two parts and it could be swiped. I wonder what should be the best way of doing that since the SlidingDrawer is now deprecated (and is not swippable). I need it to be an easy way to implement and few stress to mobile processor.
The content would be different in each item so I need to be able to access the TextViews inside them.
This is the example I wish to the item od the ListView:
The user could Swipe between both fragments and check its contents.
Any idea, advice or tutorial on this matter? Thank you very much for your attention

Use a ViewPager. Really easy to use, just extend a FragmentPagerAdapter to create the fragments to swipe between.

Related

What is the best practice for arranging Android apps with multi-screens and a fixed custom navigation bar?

I am making an app and want to make sure I am following good practices before I proceed further and potentially turn my app into a "big ball of mud" implementation.
So right now the general idea I have in my head is where you have a row of icons along the top representing the different pages you can click on. You click the button/icon and it takes you to that page.
So this icon-row along the top would be constant throughout most of the app. The only thing that would change would be the contents below that icon-row.
Is it considered acceptable practice to use fragments here? Use one main activity that has the icon-row at the top and then have the container below that "swap out" fragments based on the icon clicked? And then each page is really just a big fragment?
Does this make sense, am I following good practice? Is there a better way to do this?
I am making an app and want to make sure I am following good practices before I proceed further and potentially turn my app into a "big ball of mud" implementation.
If that happens, try a good brand of laundry detergent, at least if you are using Twitter Fabric.
So right now the general idea I have in my head is where you have a row of icons along the top representing the different pages you can click on. You click the button/icon and it takes you to that page.
A typical implementation of that in mobile apps is to use tabs that contain your icons.
Is it considered acceptable practice to use fragments here? Use one main activity that has the icon-row at the top and then have the container below that "swap out" fragments based on the icon clicked? And then each page is really just a big fragment?
Most modern tab implementations are based around using a ViewPager as the container for the tabs, so the user can swipe the content or tap on the tab to switch to different pages. ViewPager can work with plain views for its pages, but the stock PagerAdapter implementations use fragments.
Even if you elected to eschew tabs, using fragments for the pages (whether wrapped in a ViewPager or not) is reasonable.
The big thing to watch out for is memory consumption. Android devices do not have infinite RAM.[citation needed] You need to make sure that you have a modest number of fragments outstanding at any given point.
Yes, this is the proper way to use the parent activity or fragment with this "icon-row". You can use the Toolbar+menu for example, if you want to preserve the Android look, use tabs+ViewPager or use custom view.
Then, in this activity/fragment you will have a layout that will work as a fragment container. In this layout you can replace the fragments dynamically using the FragmentManager of parent activity/fragment. Each of these pages is a separate fragment.
So yes, this is good/common practice.
You may read the how-to about replacing fragments here

Using actionbartabs to display one fragment but differing data?

I'm having a design issue. I'm not sure if this is a good way to do it but here is what I want to do.
I want a way for the user to quickly swipe or click on a button to change the data that is shown in a fragment which contains a list. I thought of using tabs but it seems that's more suited if you have different fragments for each tab and using only one fragment might not be best practices.
The reason I only want to use one fragment is because that code will not change for different tabs only the data that is given to the recyclerview.
Should I go forward with this or is there a better method?

Should this be 2 fragments or 2 activities?

I have a tabbed interface for my program - there are two tabs: take photo and view photos.
As the name suggests, the user can take a photo in "take photo" and the user can view photos taken in "view photos". Right now the way its set up I use one single MainActivity and I have TakePhotoFragment and ViewPhotoFragment -- question is: does this contradict the principles in which Fragments are supposed to be used in? I don't really anticipate having both fragments displayed in a single screen (e.g. on a tablet), but I don't see how I can use one activity for each because of the limitations of the tabbed interface (when I created the activity in eclipse, I was prompted to select what kind of layout, I chose tabbed layout, and automatically code for fragments within an activity corresponding to several tabs was generated)
Can anyone help? Should "take photo" and "view photos" be fragments or activities?
It should definitely be fragments.
This does in no way contradict anything, plus I do not understand your concern about showing both fragments in a single screen. If you do not want that to happen, you just program accordingly. That is certainly not something that just happens because of the choices that you have mentioned so far.
Fragments is the best method you can use for the purpose you mentioned above. You can check the below links to know about the usage of fragments.
Creating a fragment
Fragments
android fragments
android fragments tutorial

ViewPager or Fragments?

I need to make an application that will basically be a 5 "page" quiz with true and false buttons. I don't think that a new layout/activity is needed for each "page". That would be overkill. Would a fragment or ViewPager be appropriate? Does it break any Android Guidelines? They both seem to make sense to me. Maybe fragments a little more because of a tablet/alternate layout. Any ideas would be appreciated.
I've been using the ViewPager in one of my projects, for side swiping between similar yet distinctly different views.
It is working very well.
It depends on your flow. View Pager will work well if your users can randomly go through the views. If you want things to be in a specific order then ViewPager probably won't work.
you can achieved by creating 5 pages dynamically and load that in single layout/activity
By using dynamically load pages helps In future you want to add 2 pages of question its easy to do
According to your flow u can use the this also In same activity you can change the question just on click of button.
And if you want user to revisit all question u can use view pager.

managing Persistent Visual Data (event driven buttons and ImageViews) throughout Activities of an application

I need some advice for those who are experienced making Android applications. What I would really like to have, for my application's appearance: at the top, a title-bar which is a ImageView (content is a png), and at the bottom a series of custom buttons which make up a tab-bar like thing. In between the title and the tab-bar is the Content, which may be anything... (most likely buttons)
I have been doing this by making a RelativeLayout which specifies LeftMargin and UpperMargin for x,y coordinates--
Currently all of my activities are inheriting a custom MyActivity class, which rebuilds the title and the tab-bar at the time of onCreate. This seems bad to me!
PART1)
---A solution to Persistent data
Since the "tab-bar" and the title are persistent no matter what screen you're on during this application's run-time, it makes the most sense to store them somewhere... How should I do this? Make a singleton object that the Activity's ask for?
I thought a little about the singleton object, and I'm not even sure what I would store, since the Views that are on displayed during Activity A have activity A as context, and not Activity B.
PART2)
---Animation Aesthetics
I would really like to have the "Content" (the view in the middle between title and tabbar) slide out to the left, and the new content slide in from the right. I.e, I'd like the tab-bar and the title to remain fixed while the "activities" change. is this at all possible? What should I do to achieve it?
one idea I had, was to make all of the program in one activity! I would create an animation for the Custom View in the middle, and I would override the "back" button to navigate correctly to the previous Custom View. Is that a horrible idea?
Anyone have any advice?
Read http://developer.android.com/design. Most of the design principles can be applied to apps that run on legacy releases; it's not just limited to Honeycomb and Ice Cream Sandwich. Do consider the Action Bar and Dashboard design patterns.
I don't really recommend using just one Activity -- generally, an Activity should be a separate, encapsulated, pretty well defined chunk of functionality that can execute independently of other Activities.
To avoid duplication of your UI, consider reusing XML layouts.
To avoid duplication of your logic, consider using Fragments. You should be able to mix and match them in your activities.
To achieve the animation you describe, consider implementing a ViewPager.
Using the ActionBarCompat sample app and Android Support Library, you can enjoy modern goodies like Action Bar, fragments, tabs, and horizontal sliding transitions on devices running Android all the way back to Donut (1.6).

Categories

Resources