I have an application with a single page. But I want to create another page for an information from the file that I fill up using background service. I want it look like as swipable tabs. What is the best option to do it ?
I have only 1 Activity and 1 service. Service is just for getting information from web and saving it to file. First page is for controls, second, which I want to add, is for ListView that will read from that file service is filling up (swipable tabs will be the best). I tried to use Fragments, but there is too much to rewrite in order to transfer logic to Fragment.
Your Best option is to use ViewPager and Fragments as the UI codes will be clean and will easily be obtained from internet.
The other option if you are not willing to rewrite the code is to use a Tabbed View and clicking on the tab will hide and show elements in the mainlayout( Will not have animations though)
Related
Is it advisable to stack up multiple views and depending on the preceding activity, show the appropriate widgets/views to user? e.g. To have 2 or 3 forms in 1 layout file(xml),and show one view depending on what the user wants to see.
you can use Fragments... Add the right fragment to activity based on the preceding activity.
Fragments do this. Stacked views are nice for collapsed elements. There are uses for them as well. The choice is based on your particular use case. From what you've said, I would recommend Fragments.
The nice thing about fragments is that they handle life cycle events (like activities) but without the need for serializing and parceling data to communicate among your fragments.
As for your question "Is it advisable to layer views?" I would advise against layering different forms UI. The xml design and maintenance can grow hair real quick.
Fragment is the solution in android when you want to show some specific layout to the user create 2,3 fragments android depending on the condition load the appropriate fragment.
You can go through this to get started on fragments.
https://developer.android.com/guide/components/fragments.html
Now I want to create a TabHost for 3 categories, Pizza, Spaghetti and Snack. Information will be taken form database. Is it possible to access only information of that specific category after the tab is clicked instead of creating it when the activity starts. If it is possible, which way is better.
I made something like you over a week ago and after long debugging I realized that the system loads the present tab and the one after it at the same time in case to be ready for swiping anytime you wanna do it (I mean their layouts). So if you place your database logic on the Fragments not on your Activity directly (different database logic on the different tabs), when you load your app, only the first tab database logic will be loaded, but the second tabs layout will be loaded too. Hopefully you could understand what I meant :)
I am very new to android development. I am trying to create a simple two activities based ebbok type application where activity1 is table of content and activity2 displays the details. I have a listview in Activity1 where I list the table of content. On clicking any specific content, I load activity2. In onCreate of activity2, I load the content into a string(from a txt file in assets). and display that in textView (as defined in activity2.xml). So far so good. The challenge now is to display the content page-wise because, as of now all of my string gets loaded into a single page in activity2. So I added two buttons at the bottom of activity2 (defined that in activity2.xml). My planned logic now is
get the screen height (I could get that)
get the botton height and substract 2) from 1). Now I cannot do this becuase I cannot get button height in onCreate of Activity2
and then find how much text I can fit in one page, find number of pages accordingly, use a page index and using a page delimiter, keep loading remaining text into next pages when user clicks "next" button.
So i need help with
-how to get button width as I have mentioned in 2)
-and any sample code you can share to perform 3) above will also help me.
any help here from any one of you experts out there will be much appreciated.
Using Fragements will Solve your problem.
Fragements :
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. You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running (sort of like a "sub activity" that you can reuse in different activities).
For example, a news application can use one fragment to show a list of articles on the left and another fragment to display an article on the right—both fragments appear in one activity, side by side, and each fragment has its own set of lifecycle callback methods and handle their own user input events. Thus, instead of using one activity to select an article and another activity to read the article, the user can select an article and read it all within the same activity
For More About fragements just go through this link.
Hope it will help you.
I figured out a much efficient way to display a long string across number of pages. -I display the long text into the text view and disable scrolling -I then find out the lines in the layout and lines on single screen, hence I know how many screens(pages) will the long string span across -Then whenever user clicks a button to go to next page or swipes screen to go to the next page then I use TexView.scrollTo() function to move to number of lines(as many on a screen) forward. So it becomes as good as moving to next page
I am developing an android application in which I have creted a TabActivity. For each tab I am using a separate activity and a separate layout file. Actually this activity is a details screen which shows customer information. The user can click on an item in a listview activity in order to see customer's detailed info in the tab acticity. There he can use navigation buttons to navigate through the customers In a few words, if the listview displays 10 records and the user clicks on the first item the customer details.tabactivity opens and displays detailed info. Using the navigation butons the user can see the next or previous record.
Now, I would like to use a viewflipper in the details screen in order to use animations while navigating through the records and in the end. to use fling gestures instead of buttons. Nevertheless I haven't found a proper example of how to add a tabhost/tabactivity in the flipper. I also thought to create the tabs using one layout in order to add it to the viewflipper but then I have no way to create the tabs inside the activity that hosts the viewfliper.
Any help would be apreciated. Thank you in advance.
ps. I will create a basic app of what I am talking and upload if that would be helpful
The ViewPager may be more appropriate for what you are trying to do.
I've recently decided to update my app to support the new fragments feature in honeycomb 3.0.
My Application currently works on a list view that opens different activities depending on which list item is clicked.
Using an adaptation of the code in this tutorial I have created an app that consists of only two activities, but depending on which list item is clicked the second "viewer" activity launches using a different layout xml.
Unfortunately I haven't been able to figure out how to call the old methods that had all the functionality. Should I Import all of my old activities and then call the methods into the viewer activity (I may need some advice on how exactly to do this) or should I just put all the methods directly into the same viewer activity (please consider the size of these methods(which is very large by the way)).
Once everything is working with two activities upfront then it will be a pretty simple task of "fragmenting" the app as demonstrated here
Although I haven't considered that there might be a way to allow multiple fragments to occupy the same space in an activity(If this is the case then please let me know how it's done)
Thanks
As James has pointed out you will have to move the business logic from your Activities to your Fragments.
To handle events you can create a listener Interface. The CONTAINER activity/ies will implement this interface. As fragments has access to the container activity you will be able to delegate to the container Activity the "logic" for the desired events. For this events the activity will decide whether to launch a new activity, show/hide new fragments or whatever.
I had a similar question, take a look to the question and answer: here
Although I haven't considered that there might be a way to allow multiple fragments to occupy the same space in an activity(If this is the case then please let me know how it's done)
I think its possible to allow multiple fragments to occupy the same space in an activity. Again, take a look to the answer here ... I think the concept/scope of Activity has change a bit and now an Activity can contain different Fragments which every one will allow user to do a single focused thing.
I'm not sure what you mean by "call the old methods that had all the functionality". You'll want to rewrite all of your activity classes as fragments. Check out this tutorial here (it's very concise). Basically, you'll want an activity that consists of a ListFragment and a FrameLayout. Your ListFragment will update the FrameLayout by changing to the appropriate Fragment based on which row was selected.