i have a tabHost with 3 tabs and each of them has a youtube video embeded in it. Each time i click a tab it gives another video in the tab view as such:
TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
TabSpec tab1 = tabHost.newTabSpec("Chilling");
TabSpec tab2 = tabHost.newTabSpec("Shit");
TabSpec tab3 = tabHost.newTabSpec("Gaming");
tab1.setIndicator("Chilling");
tab1.setContent(new Intent(this, ChillScreen.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
tab2.setIndicator("Shit");
tab2.setContent(new Intent(this, SadScreen.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
tab3.setIndicator("Gaming");
tab3.setContent(new Intent(this, GamingScreen.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
/** Add the tabs to the TabHost to display. */
tabHost.addTab(tab1);
tabHost.addTab(tab2);
tabHost.addTab(tab3);
Now in the activity that creats these tabs i have a button and i want it to refresh the selected tab and i do this by:
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String current_tab = tabHost.getCurrentTabTag();
if (current_tab.contains("Chilling")) {
;}
The button checks the tab selected and i want it to refresh said selected tabView. How can i do that?
I know tabHost is deprecated but my app is almost ready and i wish to finish it like this:)
thank you very much in advance
Related
My app's text editor lets a user open and edit files, I want to open the file as a new tab in the TabHost so multiple files can be open. How do I add an EditText to a newly created Tab? This is what I tried in my onCreate()
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
EditText editor = new EditText(this);
TabSpec spec1=tabHost.newTabSpec("Tab 1");
spec1.setContent(editor.getId());
spec1.setIndicator("Tab 1");
I assume the problem is `spec1.setContent(editor.getId());
You try to set an id (which was not defined by the way) as a layout id.
It won't work that way. Try:
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
EditText editor = new EditText(this);
TabSpec spec1=tabHost.newTabSpec("Tab 1");
spec1.setIndicator(editor);
if this is what you want. You can also try:
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
final EditText editor = new EditText(this);
TabSpec spec1=tabHost.newTabSpec("Tab 1");
spec1.setContent(new TabHost.TabContentFactory(){
public View createTabContent(String tag){
return editor;
}
});
I have done TabActivity with this code:
addTab(publication, "First", My_Files.class);
addTab(shop, "Second", Others.class);
private void addTab(String labelId, int drawableId, Class<?> c)
{
TabHost tabHost = getTabHost(); // The activity TabHost
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title);
title.setText(labelId);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
In these first and second tabs, I have ListViews with some context where user press it and it goes to other Activity with this code:
Intent intent = new Intent("android.app.reader.FILES");
intent.putExtra("publicatonName", "fileName");
startActivity(intent);
But there disappear my TabActivity, but I still want to use it like iPhone
UITabBar with UINavigationController
So now I am thinking that when I go to other Activity I need to change current TabActivity button class target to current and somehow my Tab Bar Activity should be visible.
Maybe someone could help me.
Thanks.
ActivityGroup, which will be the container of your other Activities. When the user clicks one of the buttons, you'd get a reference to the LocalActivityManager, and use it to start, and embed the inner activity.
get some experience from here and also
I have tabhost in my application(2 tabs),when i select tab2 the content has been dislayed has a list view ,again i have list click event here to move further another list view,here the 2tab already in selected mode and it's focus not been changed,when i click the 2tab again i need it to reload its content has loaded initially with first list view content.how can i get it.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("OPT")
.setContent(new Intent(this, TabGroup1Activity.class)));
tabHost.addTab(tabHost.newTabSpec("tab2")
.setIndicator("EDIT")
.setContent(new Intent(this, TabGroup2Activity.class)));
tabHost.setCurrentTab(1);
}
You could also re-issue another intent to refresh the tab
try public void onResume() {} method
I have an app that has 2 tabs. Each tab loads an xml file (fairly large, maybe 400 item rss file).
By default the tab doesn't get the xml until it's clicked on. I simply wanted a way to load it all when the app is first opened.
Here is the main view:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Audio Feed
intent = new Intent().setClass(this, AudioFeed.class);
spec = tabHost.newTabSpec("audio").setIndicator("",
res.getDrawable(R.drawable.ic_tab_audio))
.setContent(intent);
tabHost.addTab(spec);
// Video Feed
intent = new Intent().setClass(this, VideoFeed.class);
spec = tabHost.newTabSpec("video").setIndicator("",
res.getDrawable(R.drawable.ic_tab_video))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0); //todo: remember what tab user was last on
}
I use TabHost.setCurrentTab(x) or TabHost.setCurrentTabByTag(x).
mTabHost.setCurrentTab(1);
mTabHost.setCurrentTab(0);
For Initialization I use TabHost.OnTabChangeListener.
private OnTabChangeListener mOnTabChangeListener = new OnTabChangeListener() {
#Override
public void onTabChanged(String tag) {
if (FBIntent.EXTRA_XX.equals(tag)) {
// Current tab is xx.
... if xx not init -> ...
} else if (FBIntent.EXTRA_YY.equals(tag)) {
// Current tab is yy.
...
}
}
};
In this same method do whats the other tabs do. I mean what the other do when you click them. So you have the same thing for all tabs. Don't forget to include this same tab in the OnTabChanged() method and do the same operations again, otherwise you'll get nothing when this tab is clicked again.
I have a TabHost with two tabs. I want to know when the user clicks on either tab. How can I achieve this?
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, Main.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("watchlist").setIndicator("Watchlist",res.getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, ARActivity.class);
spec = tabHost.newTabSpec("trending").setIndicator("Trending",res.getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
I think you want to use an onTabChangeListener (http://developer.android.com/reference/android/widget/TabHost.OnTabChangeListener.html) and pass that to the TabHost. See http://developer.android.com/reference/android/widget/TabHost.html#setOnTabChangedListener%28android.widget.TabHost.OnTabChangeListener%29
You can effectively get notified every time someone switches a tab.