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.
Related
i have three activities in my application .
first one is the default activity when i slide right to left second activity should be open with its layout and when i slide left to right third one should open with its layout
i want to change the activities on sliding not only background or layout..
give me appropriate way to do this.
i m using this tab view but this is not giving any slider functionality
public class TabDemo extends TabActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_host);
TabHost tabHost=getTabHost();
// no need to call TabHost.Setup()
//First Tab
TabSpec spec1=tabHost.newTabSpec("activity 1");
spec1.setIndicator("activity 1");
Intent in1=new Intent(this, activity 1);
spec1.setContent(in1);
TabSpec spec2=tabHost.newTabSpec("activity 2");
spec2.setIndicator("activity 2");
Intent in2=new Intent(this,activity 2);
spec2.setContent(in2);
Toast toast = Toast.makeText(getApplicationContext(), "Welcome in Resident center",Toast.LENGTH_SHORT);
toast.show();
TabSpec spec3=tabHost.newTabSpec("activity 3");
spec3.setIndicator("activity 3");
Intent in3=new Intent(this,activity 3);
spec3.setContent(in3);
tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
tabHost.setCurrentTab(1);
}
}
Simplest way to create an App with Swiping functionality is in my opinion to create a new Android Application via Eclipse Wizard with following options selected:
Create Activity -> BlankActivity
Navigation Type = Tabs + Swipe
This will create an Application with (i think) 3 pages you can swipe through.
Now you can check the created files/code and change whatever you want/need to.
And as mentioned in the comments to your answer, this isn't possible with Activites, you need to use Fragments!
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()`.
I need little bit help related to android tabhost. I have 3 tabs and 3 activities. MainTab activity is "extends from TabActivity" and other 2 activities are "extends from Activity".
In MainTab activity there are two buttons Radio and CheckBox, when user click radio button then i want to display radio button view in tab2. when user click check box i want to display checkbox view. Can some gives me an idea how I can achieve this?? Below is my code.
public class MainTabHost extends TabActivity implements OnTabChangeListener{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.homeui);
TabHost tabHost = getTabHost();
tabHost.setOnTabChangedListener(this);
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, Main.class);
spec = tabHost.newTabSpec("Main Tab").
setIndicator("Main Tab")
.setContent(intent);
spec.setIndicator("", this.getResources().getDrawable(R.drawable.maintabicon) );
tabHost.addTab(spec);
intent = new Intent().setClass(this, TabA.class);
spec = tabHost.newTabSpec("Tab A").
setIndicator("Tab A")
.setContent(intent);
spec.setIndicator("", this.getResources().getDrawable(R.drawable.tabaicon) );
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
#Override
public void onTabChanged(String tabId) {
}
}
You can use SharedPreference for this. So that when you choose radio button you can change your shared value to radio and when you use Check box change value to check box and use the view in your second tab according to the shared value.
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