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;
}
});
Related
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
I have a class that extends LinearLayout. It contains simply two EditBox. On some button click, i want to load this class inside the alert Dialog. When i click on button, the alert dialog is displayed but the view class that extends LinearLayout is not displayed.The code is as follows. I am stucked into this. Can I get some solution??
public class StudentDialog extends LinearLayout {
Context context;
LinearLayout layout;
public StudentDialog(Context context) {
super(context);
this.context = context;
createStudentDialog();
}
private void createStudentDialog() {
layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
layout.setPadding(10, 10, 10, 10);
layout.setId(200);
EditText studentName = new EditText(context);
studentName.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
studentName
.setTextAppearance(getContext(), TEXT_DIRECTION_FIRST_STRONG);
EditText address = new EditText(context);
address.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
address.setTextAppearance(getContext(), TEXT_DIRECTION_FIRST_STRONG);
layout.addView(studentName);
layout.addView(address);
}
}
//Now i am calling this on some button click listener as follows. The alert dialog is displayed but not the StudentDialog.
StudentDialog dialog = new StudentDialog(this);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setView(dialog);
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
It should work if you change
alertDialogBuilder.setView(dialog);
as
alertDialogBuilder.setView(dialog.layout);
Do you want to show two edit text in a alert view just like a login dialog with button, if yes then just create a layout which you want to show in dialog view. Create a class which extends Dialog and set this layout in setContentView of onCreate of this class
I set tab without TabActivity,
so my tabHost always has an error.
please tell me how to do.
thanks.
private void setupTab(Class<?> ccls, String name, String label,
Integer iconId) {
Intent intent = new Intent().setClass(this, ccls);
View tab = LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
ImageView image = (ImageView) tab.findViewById(R.id.icon);
TextView text = (TextView) tab.findViewById(R.id.text);
if (iconId != null) {
image.setImageResource(iconId);
}
text.setText(label);
TabSpec spec = tabHost.newTabSpec(name).setIndicator(tab)
.setContent(intent);
tabHost.addTab(spec);
}
i read Android Tab-Host
to earn
It can't build.
i'm run error by tabHost cannot be resolved.
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 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.