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.
Related
I have added the details inside the displayItems activity after user click the item on Listview. The question is how can I make the URL clickable so user can got to that specific website.(The details is called from csv file). Anyone can guide me?
My Listview.java
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(ShoppingMall.this, Displayitem.class);
if (adapter.getItem(position).length > 0) {
intent.putExtra(Displayitem.EXTRA_NAME, adapter.getItem(position)[1]);
intent.putExtra(Displayitem.EXTRA_STATE, adapter.getItem(position)[2]);
intent.putExtra(Displayitem.EXTRA_ADDRESS, adapter.getItem(position)[4]);
intent.putExtra(Displayitem.EXTRA_URL, adapter.getItem(position)[5]);
intent.putExtra(Displayitem.EXTRA_NUMBER, adapter.getItem(position)[6]);
intent.putExtra(Displayitem.EXTRA_MAIL, adapter.getItem(position)[7]);
}
startActivity(intent);
}
});
My displayItem.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_displayitem);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
tvMallName = (TextView) findViewById(R.id.tv_mallname);
state = (TextView) findViewById(R.id.states);
mallAddress = (TextView) findViewById(R.id.mall_Address);
url = (TextView) findViewById(R.id.url);
phone_number = (TextView) findViewById(R.id.phone_number);
mail = (TextView) findViewById(R.id.mail);
extras = getIntent().getExtras();
String malladress = extras.getString(EXTRA_ADDRESS,"");
String mallName = extras.getString(EXTRA_NAME, "");
String mallurl = extras.getString(EXTRA_URL,"-");
String mallnumber = extras.getString(EXTRA_NUMBER,"-");
String mallstate = extras.getString(EXTRA_STATE,"");
String mallmail = extras.getString(EXTRA_MAIL,"-");
mallAddress.setText(malladress);
tvMallName.setText(mallName);
state.setText(mallstate);
url.setText(mallurl);
mail.setText(mallmail);
phone_number.setText(mallnumber);
}
Methode 1 :
TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='http://www.google.com'> Google </a>";
textView.setText(Html.fromHtml(text));
Method 2:
use android:autoLink="web" in your TextView's xml. It should automatically convert urls click-able (if found in text)
Also include android:linksClickable="true"
Put this piece of code in onClick method of of textview. This will launch the browser with the specified URL
Intent intent= new Intent(Intent.ACTION_VIEW,Uri.parse(YOUR_URL));
startActivity(intent);
I'm trying to do a simple tab app in android with four tabs tabs. My problem is that when I want to show icon and indicator, it just display only text indicator, i want to display drawable and indicator text on tabhost, this is my code :
#Override
protected void onCreate(Bundle savedInstanceState) {
//hide title bar
BasicDisplaySettings.toggleTaskBar(SimasCardMainActivity.this, false);
//show status bar
BasicDisplaySettings.toggleStatusBar(SimasCardMainActivity.this, true);
super.onCreate(savedInstanceState);
setContentView(R.layout.simascard);
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, TerbaruSimasCard.class);
spec = tabHost.newTabSpec("Terbaru").setIndicator("Terbaru",
res.getDrawable(R.drawable.menu_terbaru))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MerchantSimasCard.class);
spec = tabHost.newTabSpec("Merchant").setIndicator("Merchant",
res.getDrawable(R.drawable.menu_merchant))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, TentangSimasCard.class);
spec = tabHost.newTabSpec("Tentang").setIndicator("Tentang",
res.getDrawable(R.drawable.menu_tentang))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, FaqSimasCard.class);
spec = tabHost.newTabSpec("FAQ").setIndicator("FAQ",
res.getDrawable(R.drawable.menu_faq))
.setContent(intent);
tabHost.addTab(spec);
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++){
tabHost.getTabWidget().getChildAt(i).setPadding(0,0,0,0);
tabHost.getTabWidget().getChildTabViewAt(i).setBackgroundDrawable(null);
}
tabHost.setCurrentTab(0);
}
// #Override
public void onBackPressed() {
finish();
}
when i use
spec = tabHost.newTabSpec("Tentang").setIndicator("",
res.getDrawable(R.drawable.menu_tentang))
.setContent(intent);
it will show an icon, but when i add text on setIndicator such as setIndicator("Tentang") it show only indicator text on tabhost, i don't know where is something wrong with my code,I've tried to get increase the tab height, but it doesn't work, i hope someone can help me to solve my problem. thank you
Remove this tabHost.getTabWidget().getChildTabViewAt(i).setBackgroundDrawable(null);
and replace it with
tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.menu_tentang);
i have done it like this and it is working fine
Resources ressources = getResources();
TabHost tabHost = getTabHost();
Intent addfriend = new Intent().setClass(this, yourclass1.class);
Intent mailfriend = new Intent().setClass(this, yourclass2.class);
tabHost.addTab(tabHost.newTabSpec("child1").setIndicator("your tag",getResources().getDrawable(R.drawable.youpng)).setContent(addfriend));
tabHost.addTab(tabHost.newTabSpec("child1").setIndicator("your tag",getResources().getDrawable(R.drawable.yourpng)).setContent(mailfriend));
tabHost.getTabWidget().getChildAt(0).setBackgroundColor(getResources().getColor(R.color.anycolor));
tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.yourpng);
tabHost.getTabWidget().getChildAt(1).setBackgroundColor(getResources().getColor(R.color.anycolor));
tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.youpng);
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
The question is: I have a TabHost with 4 tabs (see code below) and I got a Button in MainMenuActivity class. The Button is set up with a OnClickListener and if it is clicked I want it to go to the second tab. I have tried with setCurrentTab(1) but that just messed the project up. What can I do?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setTabs() ;
}
private void setTabs()
{
addTab("Home", R.drawable.tab_home, MainMenuActivity.class);
addTab("Calculate", R.drawable.tab_search, SpinnerClass.class);
addTab("Search", R.drawable.tab_home, ScrollView1.class);
addTab("Premium", R.drawable.tab_search, ScrollView2.class);
}
private void addTab(String labelId, int drawableId, Class<?> c)
{
TabHost tabHost = getTabHost();
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);
}
tabHost.setCurrentTab(index) is the right way to go. What's the problem when you use it?
"setCurrentTab(int) opens the tab to be displayed by default, specified by the index position of the tab."
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.