I have created a TabActivity in my android application. When user selects the second tab, an alert dialog will appear. Is there any way to navigate to the previous tab when user clicks the cancel button for the dialog box.
regards
dj
I found the solution here:
Android - Switch Tabs from within an Activity within a tab
In my case, I have used the solution of 'GrandPrix'.
I think you need to first know about the Tab Widget:
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
http://www.androidpeople.com/android-tabhost-tutorial-part-1/
You can set the tab using setCurrentTab method:
tab_host.setCurrentTab(2); // 2nd tab button is showing initially
same way, you can set the tab-button on the cancel button.
Related
I am trying to integrate Chrome Custom Tabs in my Android App. Here is the requirement where I am stuck:
1. List of pdfs being shown in GridView. The user when clicks on any pdf will be opened on custom tabs. Here I will pass the position of item in GridView.
2. This position will be used for selection. There will be a SELECT action on custom tab. When the user clicks on SELECT, the custom tab should close passing the position back to the activity so that I can mark that item in GridView selected.
Now the problem is in closing the Custom Tab and passing the data back to activity. Any help in this regard will be highly appreciated.
There is no such support currently to close chrome custom tab programatically.
But you can close it by starting your previous activity from where you launched chrome custom tab.
For this, set your activity launchMode as "singleTask" and then start your activity with FLAG_ACTIVITY_CLEAR_TOP when ACTION button is clicked.
Then chrome custom tab will be automatically closed and the previous activity will be shown from where chrome custom tab was opened.
You can check details from here: How to close chrome custom tabs .
I am a beginner in android. I have created Tabs using ActionBar tabs. Now I want to implement, when the user in in first tab and clicks back Button activity should close or when the user is in second tab, he clicks the backbutton the app should show the first tab, which will make it as the home tab. I tried using popupbackstack() but it always closes the activity no matter what tab i am in.
please guide me. Thanks in advance.
The easiest way would be record the tab state (i.e., which tab is showing) in the host activity, and override the onBackPressed() method to do what you want.
Some tips:
remember to save the state(override the onSavedInstanceState() and save the tab state) to make you activity works right after restore from onPause().
read about android's recommended navigation style here. What you designed is a little bit different from what android suggests.
I have one activity, with five tabs. When I launch the application by default first tab (with 0 index) is selected.
I want it should work like when I launch the application, none from the five tabs should be selected. when I click on particular tab then it should show UI according to the selected tab.
Make the initialization routine select one of the tabs.
I'm creating the 3 tabs dynamically based on example here http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
the application works well except one issue.
when I launch app and then click the Back Button then the app closes.
I launched the app by clicking on the application icon.
now I can see 6 tabs. each time I repeat this process, it keeps on adding 3 tabs.
when ever I use Menu button instead of back Button then it doesn't add 3 tabs.
anything going wrong here, how can I fix it?
thanks
Are you creating the tabs at onResume() or onStart()? Try to create them at onCreate()
or delete the tabs by onPause with something like:
LinearLayout tabbar = (LinearLayout) findViewById(R.id.tabbar);
tabbar.removeAllViews();
so my app has two tabs
tab 1 is a login page then
tab 2 is a user details
the user needs to loginfrom tab 1 then only details would load from tab 2 so if the user didn't login and goes to tab 2, an alertdialog would show the problem is, after going back to tab 1 and if the user does not login again prior to tab 2, the alertdialog would not show again. I'm not sure if I should use onRestart or onPause or something..
SOLVED!
the easiest way to do is to set the flag in the tabhost .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
thanks for the help guys :D
Change Your Application Flow.
make one tab represents a set of activity.
make use of activity group.