android:how to Reload the TabActivity when tab press? - android

I have Tab Based Application where i want to Reload the Tab activity when tab are select again.. In my application when i select the Tab again the view are coming as old output It is not reloading the page..so how can i reload the page by clicking the Tab again and again without showing old view?

switching of tabs calls onPause and onResume functions, so in order to refresh the page, cut paste the functionality provided in onCreate to onResume...

Related

Android: Fragments in swipe view

I have an activity with 3 tabs. Tab A, Tab B, Tab C. Tab A loads data from a server. Tab B and C have text fields on them with buttons. Each tab is implemented with a different fragment.
My issue is when I type on a text field in Tab B and swipe to Tab C, the text field from Tab B is not cleared. I would like for it to be cleared. Is there a way to recreate or reload the fragment when I swipe to the selected tab?
For Tab A to finish loading data from the server takes some time, so I created a progress dialog while the operation is running. Now the progress dialog works correctly, but if I swipe from Tab A to Tab B to Tab C back to Tab B, the progress dialog is shown. The progress dialog is shown in the onCreateView() method of the fragment for Tab A. I don't understand how this is possible. I think it is because the fragments are stilling running even when I am on different tabs. Is it possible for the fragments to only run/start when the user swipes to the selected tab? Also, is there any code that I should run in the onTabUnSelected() method? Is there a way to end a fragment in that method?
Edit:
I figured out how to have the text fields cleared when I leave the fragments. I overrided the following:
public class MyFragment extends Fragment
#Override
public void setMenuVisibility(final boolean visible) {
super.setMenuVisibility(visible);
if (!visible) {
...
}
}
Now the text fields are cleared when I swipe from tab to tab. I'm not sure if this is the best way to solve the problem, so if somebody else has a better way, please let me know. I tried to implement the same function in the other fragment to dismiss the dialog when the fragment is not visible, but it does not work.
Edit 2:
For some reason, the onCreateView() method for fragment A is being run when swiping from Tab C to Tab B. Fragment A is loaded on Tab A. Shouldn't the onCreateView() method for fragment A only be run when Tab A is selected?
Edit 3:
I figured out what the problem. Android automatically sets the value of setOffscreenPageLimit(int) to setOffscreenPageLimit(1). This automatically loads the next tab in the background. So as a workaround, I will create a progress bar/spinner on the screen itself instead of creating a progress dialog.
I will try answer your queries one by one.
See this link and this link to learn how to communicate between fragments. i found second link (vogella) more useful practice.
its is absolutely fine that on tab A is working in background on swiping to Tab B and C. You need to understand that your all 3 tabs belongs to one activity that may contain three different fragments.

Android actionbar tabs: content of each tab is recreated everytime I click on that tab

I am developing an app that uses ActionBar navigation, I have 3 tabs (I dont use tabhost) as image below:
In the first tab, a fragment named FragmentListItem will be shown, if I click on Item1, FragmentListItem will be replaced by another fragment named FragmentItemDetails, that shows details of the selected item.
My problem is, when I select Tab2 or Tab 3, and then I reselect Tab1 again, what I get is not FragmentItemDetail anymore, it is FragmentListItem instead.
So, why is that? If I want FragmentItemDetail still be there instead of FragmentListItem, how to do that?
Moreover, when I press Back button (when Tab1 is selected), I want FragmentListItem will be shown again. I realise that Fragment class has no onBackPressed method to implement.
There are different solutions to this issue.
One possible solution is to use an own FragmentManager for this tab. This is possible with the getChildFragmentManager() method of Fragments.
Another solution could be a flag to identify which Fragment was shown as last on Tab1. If you know which Fragment was shown as last you could show this one by search this Fragment in your BackStack with the findFragmentByTag(tag) method of FragmentManager.
But I recommend you to try the first Option. If each tab has his own stack you have less work with your BackButton.

Tabs disappears in TabActivity after it goes to other Activities

In my app I have four tabs in the bottom of my main screen. When the user click in one of the tabs in the bottom it open an Activity and the user needs to fill up a form, after the form is done it returns to one of the TabActivities.
Everything works well, except when the form is save its supposed to go to the Activity an show the four tabs in the bottom. The problem is that the tabs in the bottom disappear.
I thought the if Im calling the TabActivity it will always show the tabs that were assign in the XML layout.
Okay you have to go for ActivityGroups. But in later version of android Activity Group is deprecated and hence you have to go for fragments or views. Here are few links which will get you started.
ActivityGroup Example
http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/
http://united-coders.com/nico-heid/use-android-activitygroup-within-tabhost-to-show-different-activity

Android : How to call the first activity in the ActivityGroup when I click the same tab again?

I am using a tab application in which I am using ActivtyGroup to embedded many views. If I click the same tab after swiching between many views, I cannot view the first activity in the activity group. It remains in the activity that I am currently focusing.
How can I go back to first activity or call the setContent() method of TabHost?
Thank you..

Android Tabs problem

I have used 2 tabs in my app.
when i click on first tab it is showing an list view( default) and when i click on any particular item in list view it is taking me to the next activity to display the selected data. Here when i click on tab again i want that i should go to the listview screen which is default screen.
but nothing happens on clicking the tab but when i press the back button i m going back on the screen. but i want to go to home list view screen on tab click,
pls help me in this case...
You say you start a new Activity. This one can not call the first Activity where you have the tabs. Am I right that your new activity just shows the two tabs as well?
What you could do is the following:
In the second Activity react to the onclick of the tab. When clicked call finish() to close the Activity.
I am pretty sure, that you don't need to do the following. But I write it, if you need it for something in the future :).
In the first Activity call the next through startActivityForResult(...)
In the first Activity overwrite the onActivityResult method. there you can switch to the tab with the list.

Categories

Resources