I am doing application with TabHost activity. I have 5 different class in that 4 class inserted into TabHost view. In one particular class i have list view with onItemclicklistener. while clicking the list view, it goes to different activity(ie 5th class). I want to place the clicked activity in TabHost. (ie) whenever i click the list view, the calling activity should appear in TabHost.But now it appears without tab host. i want to place Tab host in 5 th class by clicking listview. I dont know how to do this, if any one having idea pls let me know and guide me how to do this.
host= (TabHost)findViewById(android.R.id.tabhost);
host.setup();
TabHost.TabSpec spec;
// Create an Intent to launch the first Activity for the tab (to be reused)
Intent i = new Intent().setClass(this, library.class);
spec = host.newTabSpec ("FirstGroup").setIndicator("Library",getResources().getDrawable(R.drawable.imagename)).setContent(i);
host.addTab(spec);
u have to add your all activity like this(here Library)
Related
My android app has a tabhost with 5 tabs.
The problem is when I use setCurrentTab(2).Android start activity on the first tab then it start activity on the third tab. I find out that when I use method addTab of TabHost class,it also start activity in the first tab.
if (mCurrentTab == -1) {
setCurrentTab(0);
}
I read my thread in stackoverflow like:https://stackoverflow.com/questions/9978231/android-when-i-put-setcurrenttab-for-tabhost-it-loads-the-first-added-tab-ac
Cause My client requirement, I can't reorder tabs.When the TabActivity start,I only want start activity in the third tab ,How can I do that?
If you want to prevent loading of your fragment then put your in onVisible. Use this class UserVisibleHintFragment
It will help you to prevent advance loading.
use setCurrentTab(2) after addTab methods. Better use it at the last line of onCreate of your TabActivity
As you can see from the pic that I attached,when app android starts,it will launch activity from third tab and it read user's mail address in android device then post it to server.After that server will return user_id,I will save user_id in app memory.When user click on first tab which has an activity that contain a webview ,I will get this user_id from app memory then pass to url of webview.
If the activity in the first tab start first, the user_id will be blank.
Your question does not tell us how you are constructing your tabs. If you can post the bit of code on how you are building the tabs then we may be able to help you better.
Below is a simple way of building the tabs using TabHost. The tabHost.setCurrentTab(2); below just works fine...
TabHost tabHost = getTabHost();
// Tab for About
TabSpec aboutspec = tabHost.newTabSpec("About");
aboutspec.setIndicator("About", getResources().getDrawable(R.drawable.icon_about_tab));
aboutspec.setContent(new Intent(this, AboutActivity.class));
// Tab for Contacts
TabSpec contactsspec = tabHost.newTabSpec("Contacts");
contactsspec.setIndicator("Contacts", getResources().getDrawable(R.drawable.icon_contacts_tab));
contactsspec.setContent(new Intent(this, ContactsActivity.class));
// Tab for Resources
TabSpec resourcesspec = tabHost.newTabSpec("Resources");
resourcesspec.setIndicator("Resources", getResources().getDrawable(R.drawable.icon_resources_tab));
resourcesspec.setContent(new Intent(this, ResourcesActivity.class));
// Adding all TabSpec to TabHost
tabHost.addTab(aboutspec);
tabHost.addTab(contactsspec);
tabHost.addTab(resourcesspec);
// set the current tab to Resources
tabHost.setCurrentTab(2);
Hope this helps you resolve your problem.
I have created 2 tabs, these 2 tabs individually when on clicked open their respective layouts defined in their activity.
All i want now is to show a different layout on my screen when Tab activity is called. E.g. I don't want to show the content of of the tabs but the content of another layout.
How can i do it?
This is what i was trying to do.
Intent intent1 = new Intent(this, FacebookLoginPage.class);
tabHost.addTab(tabHost.newTabSpec("Facebook").setIndicator("",
res.getDrawable(R.drawable.ic_launcher)).setContent(intent1));
Intent intent2 = new Intent(this, TwitterLoginPage.class);
tabHost.addTab(tabHost.newTabSpec("Twitter").setIndicator("",
res.getDrawable(R.drawable.ic_launcher)).setContent(intent2));
Intent intent3 = new Intent(this, GmaiLoginPage.class);
tabHost.addTab(tabHost.newTabSpec("Gmail").setIndicator("")
.setContent(intent3));
tabHost.setCurrentTab(2);
tabHost.getTabWidget().getChildAt(2).setVisibility(View.GONE);
Is this what you want to do?
Open an activity which shown two tabs and additional information. If one of the tabs is selected then open an activity showing the contents for that tab but not the tabs itself.
In this case consider using a "normal" activity A containing a TabHost and whatever layout you want. If the tab is selected start a new activity B showing the content for that tab. With the back-key navigate back to the first activity A and select the other tab, e.g.
Alternatively you might embed the TabHost (may be as fragment) in activity B also to directly switch between tabs.
I'm using TabHost to display 3 tabs within my application (dashboard, orders and customers). Each of these is a seperate Activity containing a ListView and is working correctly. They all feature an 'endless scrolling' system like within Android Marketplace and retain their positions within the ListView when you switch between different tabs. When you click on an item within the ListView it currently loads up a brand new Activity full screen and leaves the TabHost. I'd like to load up these Activities within the TabHost (eg. Click on a specific customer within the customers list which then takes you to view the customers details whilst remaining within the customers tab. You can then return to the customers list without loosing your position/reloading the list). I've read about ActivityGroup and ViewFlipper but I'm struggling to suss out how to achieve the behaviour I desire.
mTabHost = getTabHost();
mTabHost.setOnTabChangedListener(this);
TabSpec spec;
String Tab_title3 = "NameofTab";
TextView txtTabInfo3 = new TextView(this);
setUpTextView(txtTabInfo3);
txtTabInfo3.setText(Tab_title3);
intent = new Intent();
intent.setClass(this, YourClass.class);
spec = mTabHost.newTabSpec(Tab_title3).setIndicator(txtTabInfo3)
.setContent(intent);
mTabHost.addTab(spec);
So if YourClass is a ListActivity the inside you can put a pop up dialog for example with another List with customer details and then you can add a close button. For your dialog you can setup a custom view a list view with an adapter or something else.
For example in a method:
buildMyDialog(){
final Dialog dialog = new Dialog(this);
lv2=new ListView(this);
lv2.setAdapter(mAdapter2);
//....
final Button cancelButton=new Button(this);
dialog.setContentView(lv2);
dialog.show(
}
Firstly, Im new to android but have years of various other programming experience on unix, windows,but not with Java or android.
Im wanting to display a tab with 3 tabs, each having a different layout file (which works).
Im working on displaying a "blank" template and then the data is retrieved from an XML file once the user points a setting to one (i.e. via shared preferences).
My problem is that the function populateXMLCharacter is never called (using breakpoints). The tab activity always displays "", which is a strig the string.xml.
Actually putting a breakpoint in the oncreate function never gets called either. Ive tried using a call to populateXMLCharacter in onResume, but it too never gets called.
Im thinking its because of the call to the tab:
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
// Do this and the same for all tabs
spec = tabHost.newTabSpec("Description").setIndicator("Description",
res.getDrawable(R.drawable.android)).setContent(R.layout.tab_harp_description);
tabHost.addTab(spec);
Should I be using an intent? I thought the layout was created in a seperate function (in this case harpCSDescription.java and then this allows that activity to be inserted into the tabhost?
other functions:
public class harpcsDescription extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView (R.layout.tab_harp_description);
}
//#Override
protected void onResume()
{
// NOW WE ADD DATA TO THE TEMPLATE
populateXMLCharacter();
}
public void populateXMLCharacter()
{
Ive tried using intents in the following manner but it simply crashes before any breakpoints are reached.
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
Can some one please guide me to what I should be doing to create an activity with data that is retrieved AFTER the tab is created?
I think you need an intent. To attach an activity to a tab, write the following in the tab host:
Intent intent = new Intent(this, MyActivity.class);
and then in the tab spec write:
tabSpec = tabHost.newTabSpec("name").setIndicator(this.getString(R.string.name)).setContent(intent)
Then in the MyActivity class, you can specify the layout and load the XML data to populate the tab in the onCreate() method. You can use a different activity for each tab.
I'm trying to notify my activity when the relevant tab is selected.
Consider the follwoing situation:
MainActivity:
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, HomeActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("home").setIndicator("Home",
res.getDrawable(R.drawable.ic_tab_home))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, ProceduresActivity.class);
spec = tabHost.newTabSpec("procedures").setIndicator("Procedures",
res.getDrawable(R.drawable.ic_tab_checklist))
.setContent(intent);
tabHost.addTab(spec);
Now, the first time my second tab is selected, the onCreate method of ProceduresActivity is called.
What I want to be alble to do is, within ProceduresActivity, to be notified whenever tab 1 and tab 2 (mine) are selected.
I tryed overriding onPause and onResume within ProceduresActivity however those are only called when the MainActivity is pasued / resumed and not when I switch tabs...
So in other words I want ProceduresActivity to do something whenever the user selects second tab, and not only the first time.
Can someone help me please?
Thanks, Luca.
Hmmm. This seems like it might be a little difficult (I'm not even sure it's possible) to achieve. There are two ways I can see that you could achieve the same results.
The first way is by have the first tab refresh it's data/information when the user goes back to it. This can be done in the onResume() and by adding a flag to it. Pretty simple.
If you need your activity to do something that will take some time, you can make an ActivityGroup. It's basically a controller for multiple activities. It starts them all at the same time and just chooses which one is shown at once. This means that (in your case) both activities would be running, but only one would be shown. When you want the first tab to do something while the user is using the second tab, you go to the ActivityGroup (which is like a controller) and tell it to do whatever you want with the first tab.
The only problem I see with the ActivityGroup route is binding it to your tabs, but there are many workarounds for this.
Maybe this can help you, i use this to perform an action when the tabs change. But maybe you can alter it to do a specific action with every tab?
getTabHost().setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
//TODO, action to be performed
}
}
});