I am using a Tab host two show two list on two tabs but I want that when click on second tab then it should reload the first tab data.How is it possible?
My code is like this
TabHost tabs = (TabHost)findViewById(R.id.tabhost_spices);
tabs.setup();`enter code here`
TabHost.TabSpec tab1 = tabs.newTabSpec("tab1");
tab1.setContent(R.id.list_spices_fav);
tab1.setIndicator("Favorite",getContext().getResources().getDrawable(R.drawable.tab_fav_icon));
tabs.addTab(tab1);
// create tab 2
TabHost.TabSpec tab2 = tabs.newTabSpec("tab2");
tab2.setContent(R.id.list_spices_categories);
tab2.setIndicator("View List",getContext().getResources().getDrawable(R.drawable.tab_cat_icon));
tabs.addTab(tab2);
Here is a tutorial,This Help me- link
Extends your activity with TabActivity
TabHost tabHost;
tabHost = getTabHost();
Resources res = getResources();
TabSpec tabspec1 = tabHost.newTabSpec("").setIndicator("Tab1",res.getDrawable(R.drawable.ic_launcher)).setContent(new Intent(this, FirstActivity.class));
tabHost.addTab(tabspec1);
TabSpec tabspec2 = tabHost.newTabSpec("").setIndicator("Tab2",res.getDrawable(R.drawable.ic_launcher)).setContent(new Intent(this, SecondActivity.class));
tabHost.addTab(tabspec2);
For refreshing the data of new Tab you have to keep the code for refereshing the data inside onResume() of that Activity because when TabActivity is created its all the tabs make a call to the respective Activities calling its onCreate()'. So, when you click the Tab once its loaded itsonResume()method is called and notonCreate()`.
Related
I have Tab host contains Three tabs "STEP 1,STEP 2,and STEP 3". Main Tab Host
Activity "MainActiveTab" is Parent activity ,child Activity "TabActStep_1,TabActStep_2,TabActStep_3 " resp.
I Want to access on EditText and Other Value from child Tab Activity like "TabActStep_1,TabActStep_2,TabActStep_3 " .
//Assign id to Tabhost.
TabHostWindow = (TabHost) findViewById(android.R.id.tabhost);
//Creating tab menu.
TabHost.TabSpec TabMenu1 = TabHostWindow.newTabSpec("First tab");
TabHost.TabSpec TabMenu2 = TabHostWindow.newTabSpec("Second Tab");
TabHost.TabSpec TabMenu3 = TabHostWindow.newTabSpec("Third Tab");
//Setting up tab 1 name.
TabMenu1.setIndicator("STEP 1");
//Set tab 1 activity to tab 1 menu.
TabMenu1.setContent(new Intent(this, TabActStep_1.class));
//Setting up tab 2 name.
TabMenu2.setIndicator("STEP 2");
//Set tab 3 activity to tab 1 menu.
TabMenu2.setContent(new Intent(this, TabActStep_2.class));
//Setting up tab 2 name.
TabMenu3.setIndicator("STEP 3");
//Set tab 3 activity to tab 3 menu.
TabMenu3.setContent(new Intent(this, TabActStep_3.class));
//Adding tab1, tab2, tab3 to tabhost view.
TabHostWindow.addTab(TabMenu1);
TabHostWindow.addTab(TabMenu2);
TabHostWindow.addTab(TabMenu3);
This is "MainActiveTab" Here I Want To Get Child Tab Activity Values EditText. etc
Am Try to Send Value from Child Tab Like This
Intent intent = new Intent(getApplicationContext(), MainActiveTab.class);
// Intent intent = new Intent(getApplicationContext(),MainActiveTab.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("name","tab");
// intent.putExtra("HouseName", strHouseName);
startActivity(intent);
This passing Value Get From Main Tab in MainActiveTab Using This Code Using Here
Bundle bundle = getIntent().getExtras();
String id=bundle.get("name").toString();
Declaring intent function on child Tab the that Tab is Showing "Unfortunately App Has Stopped" I Hope You Can Help Me.Thank You !!!
You cannot directly send a value from Activity to a Fragment.You have use an interface to achieve that.
Fragment1->Interface->ActivityClass->Fragment2.
Hi I am creating an application. In this I need to display a TabBar in all Activities. I set the TabBar bottom using 4 tabs; home, contact, about and call us.
Inside home tab I have some buttons. When I click inside home any button that time I need to move some other Activity. Using intent I moved to another Activity but here the TabBar was not displayed. However, I need to display the same TabBar in all Activities. If any one knows how to do this, please suggest a solution to me.
DefenceLaywer.java:
public class DefenceLaywer extends TabActivity {
TabHost tabhost;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabhost = (TabHost)findViewById(android.R.id.tabhost);
TabSpec firstTabSpec = tabhost.newTabSpec("Home");
TabSpec secondTabSpec = tabhost.newTabSpec("Claimonline");
TabSpec thirdTabSpec = tabhost.newTabSpec("CallUs");
TabSpec fourthTabSpec = tabhost.newTabSpec("AboutUs");
// TabSpec thirdTabSpec = tabhost.newTabSpec("Interactive");
firstTabSpec.setIndicator("Home", getResources().getDrawable(R.drawable.home));
secondTabSpec.setIndicator("ContactUs", getResources().getDrawable(R.drawable.contactus));
thirdTabSpec.setIndicator("CallUs", getResources().getDrawable(R.drawable.callus));
fourthTabSpec.setIndicator("AboutUs", getResources().getDrawable(R.drawable.aboutus));
firstTabSpec.setContent(new Intent(this,HomeTab.class));
secondTabSpec.setContent(new Intent(this,ContactUs.class));
thirdTabSpec.setContent(new Intent(this,CallUs.class));
fourthTabSpec.setContent(new Intent(this,AboutUs.class));
tabhost.addTab(firstTabSpec);
tabhost.addTab(secondTabSpec);
tabhost.addTab(thirdTabSpec);
tabhost.addTab(fourthTabSpec);
}
}
use fragments in activity and set that activity on tabspecs.
To learn FrAgment use following lin:
http://developer.android.com/guide/topics/fundamentals/fragments.html
and for how to use fragments to implement tab, follow followig tutorial:
http://android.codeandmagic.org/2011/07/android-tabs-with-fragments/
i need to get the Activitys initialize , before anyone click on them . That is cause i have a video in one of them , and i need to have that Activity created to play the video from another tab (or activitys) .
I have this code to initialize the tab content but not the activitys into them :
//Init Tabs
Resources res = this.getResources();
TabHost tabHost = getTabHost();
tabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
setupTab(tabHost,MyInitActivity.class,res.getDrawable(R.drawable.ic_tab_icon),res.getString(R.string.tab_init));
setupTab(tabHost,MusicGroupActivity.class,res.getDrawable(R.drawable.ic_tab_icon),res.getString(R.string.tab_playList));
setupTab(tabHost,SearchActivity.class,res.getDrawable(R.drawable.ic_tab_icon),res.getString(R.string.tab_search));
setupTab(tabHost,VideoActivity.class,res.getDrawable(R.drawable.ic_tab_icon),res.getString(R.string.tab_video));
I have seen code like this to try it :
tabHost.setCurrentTab(number);
but that seems to not run when you change immediately cause when i do
Context context = getTabHost().getChildAt(3).getContext();
it throws to me a null exception.
Anyone knows how to do this?
ADDED
private void setupTab( TabHost mTabHost,Class<? extends Activity> activityclass,Drawable image, String tag)
{
View tabview = createTabView(mTabHost.getContext(),image,tag);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new Intent(this, activityclass));
mTabHost.addTab(setContent);
}
Thanks for all
I do the following in the onCreate() (say i have 4 tabs)
tabHost.setCurrentTab(0);
tabHost.setCurrentTab(1);
tabHost.setCurrentTab(2);
tabHost.setCurrentTab(3);
tabHost.setCurrentTab(Tab_I_Want);
I want to have a TabHost which consists of two tabs: one created from View (R.id.something) and the second one from Activity.
So I do that like this:
mTab = (TabHost) findViewById(R.id.tabhost);
mTab.setup();
TabHost.TabSpec spec = mTab.newTabSpec("All");
spec.setContent(R.id.all_tab); // Created from View
spec.setIndicator("All", getResources().getDrawable(R.drawable.emo_im_cool));
mTab.addTab(spec);
Intent intent = new Intent().setClass(this, TasksDone.class);
spec = mTab.newTabSpec("Done");
spec.setIndicator("Done", getResources().getDrawable(R.drawable.emo_im_happy));
spec.setContent(intent); // Created from Intent
mTab.addTab(spec);
After that the content on the first tab isn't visible, but it's there because I see reaction on my clicks.
But it appears if I set the setContent of a second tab as a View instead of intent.
Do you guys know why the content on the first page is invisible?
Mh, have you tried spec.setContent(R.layout.all)? I assume there should be a layout id, not the id of a view-object.
The root of the problem was a mistake in xml.
Following is the example of tabs with intent data.
While debugging i found that always when first tab we add in tab host in our case following tab
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("list")
.setContent(new Intent(this, List1.class)));
oncreate method of "List1" intent get called regardless it is our current tab or not even if if i define tab2 as a current tab how to fix this ?
public class Tabs3 extends TabActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("list")
.setContent(new Intent(this, List1.class)));
tabHost.addTab(tabHost.newTabSpec("tab2")
.setIndicator("photo list")
.setContent(new Intent(this, List8.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
// This tab sets the intent flag so that it is recreated each time
// the tab is clicked.
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("destroy")
.setContent(new Intent(this, Controls2.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
}
}
setDefaultTab(1);
seems not to be working in TabActivity when separate Activities are used as Tab Content.
Use following instead of this method,
tabHost.setCurrentTab(1);
This will set "photo list" (i.e second tab) as the selected or default tab...
I have found this same behavior as well, and I do not have a specific fix. But I do know of a work-around.
Instead of attaching Activities to each tab, attach a View to each tab. You can then handle the data passing very easily as each view will be in the same Activity. This also eliminates the need to pass information using Intents. Furthermore, you can create (or inflate) your Views as you need them and with more control.
Good luck,
-scott