Tab layout issue in Froyo - android

I have created a tab based app, in one of the tab, there is also inner tab where some data is displayed in tabular format using adapter. It is perfectly ok in all devices with Android 2.1. But in all the devices with Android 2.2 devices, it is just showing only first tab only with black screen above. I have given two different screenshot for the reference.
Screenshot of 2.1 device
Screenshot of 2.2 device
XML for tabactivity
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/myinfotrackerlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="bottom"
android:isScrollContainer="false"
android:scrollbarAlwaysDrawHorizontalTrack="false"
android:scrollbarAlwaysDrawVerticalTrack="false"
android:scrollbars="none"
android:background="#FFFFFF"/>
</LinearLayout>
</TabHost>
Code for Tabactivity
public class MyInfoTracker extends TabActivity {
private int tabid = 0;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myinfotracker);
try{
final TabHost innerTabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
Intent myint = this.getIntent();
tabid = myint.getIntExtra("tab_id", 0);
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, MyinfoActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
intent.putExtra("addType","CD4");
// Initialize a TabSpec for each tab and add it to the TabHost
spec = innerTabHost.newTabSpec("CD4Count").setIndicator("CD4 Count").setContent(intent);
innerTabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, MyinfoActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
intent.putExtra("addType","VL");
spec = innerTabHost.newTabSpec("ViralLoad").setIndicator("Viral Load").setContent(intent);
innerTabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, MyinfoActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
intent.putExtra("addType","Wt");
spec = innerTabHost.newTabSpec("Weight").setIndicator("Weight").setContent(intent);
innerTabHost.addTab(spec);
innerTabHost.setScrollbarFadingEnabled(false);
innerTabHost.setScrollContainer(false);
innerTabHost.setCurrentTab(tabid);
}catch(Exception e){}
}
}
What may cause this type of problem?

It is not at all tab related prob. In onCreate() there is a code-
datePickerDialog = new DatePickerDialog(getParent(), ButtonTestDateListener,
mYear, mMonth, mDay);
I have just declare the mYear, mMonth and mDay as Integer, but no initialization was there. It is working fine in 2.1, but giving prob in 2.2. Thats why it is giving such problem.

Related

Switch between tabs via swipe in android

I was create android application with tab and TabHost but users cant switch between tabs via swipe.
I use TabActivity for this app. Users most click on tabs for switch between tabs or activities.
MainActivity.Java :
public class MainActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources ressources = getResources();
TabHost tabHost = getTabHost();
//Home Intent
Intent intentHome = new Intent().setClass(this, HomeActivity.class);
TabSpec tabSpedHome = tabHost
.newTabSpec("Home")
.setIndicator("",ressources.getDrawable(R.drawable.icon_home_config))
.setContent(intentHome);
//Search Intent
Intent intentSearch = new Intent().setClass(this, SearchActivity.class);
TabSpec tabSpedSearch = tabHost
.newTabSpec("Search")
.setIndicator("",ressources.getDrawable(R.drawable.icon_search_config))
.setContent(intentSearch);
//Archive Intent
Intent intentArchive = new Intent().setClass(this, ArchiveActivity.class);
TabSpec tabSpedArchive = tabHost
.newTabSpec("Archive")
.setIndicator("",ressources.getDrawable(R.drawable.icon_archive_config))
.setContent(intentArchive);
//Download Intent
Intent intentDownload = new Intent().setClass(this, DownloadActivity.class);
TabSpec tabSpedDownload = tabHost
.newTabSpec("Download")
.setIndicator("",ressources.getDrawable(R.drawable.icon_download_config))
.setContent(intentDownload);
//Conctactus Intent
Intent intentConctactus = new Intent().setClass(this, ContactusActivity.class);
TabSpec tabSpedConctactus = tabHost
.newTabSpec("Conctact us")
.setIndicator("",ressources.getDrawable(R.drawable.icon_contactus_config))
.setContent(intentConctactus);
//AddAllTab
tabHost.addTab(tabSpedHome);
tabHost.addTab(tabSpedSearch);
tabHost.addTab(tabSpedArchive);
tabHost.addTab(tabSpedDownload);
tabHost.addTab(tabSpedConctactus);
//Set Default Tab
tabHost.setCurrentTab(0);
}
}
And activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
TabActivity has been deprecated for over three years. Please use another tab solution. Particularly if you want tab contents to be able to be swiped, use ViewPager for the tab contents and a tabbed indicator (e.g., PagerTabStrip) for the tabs.

Tab bar not showing when call new activity

My code
View view = getLocalActivityManager().startActivity("main_jobs",
new Intent(context,Job_Description.class)
.putExtra("line", str_line).putExtra("limit",str_limit)
.putExtra("limit",""+0)
.putExtra("Alert", false)
.putExtra("str_location", str_loc)
.putExtra("str_Descrption",str_descjob)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
setContentView(view);
I am using this code to open new activity with tab but tab bar not showing and
not any error get
please help me how we can show tab bar to open new activity
Thanks in Advance
Sample Example :
Consider three tabs here
First in MainActivity.java
public class MainActivity extends TabActivity {
private static final String TAB1 = "TAB1";
private static final String TAB2 = "TAB2";
private static final String TAB3 = "TAB3";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabSpec tab1 = tabHost.newTabSpec(TAB1);
tab1.setIndicator(TAB1);
Intent Intent1 = new Intent(this, Tab1.class);
tab1.setContent(Intent1);
TabSpec tab2 = tabHost.newTabSpec(TAB2);
tab2.setIndicator(TAB2);
Intent Intent2 = new Intent(this, Tab2.class);
tab2.setContent(Intent2);
TabSpec tab3 = tabHost.newTabSpec(TAB3);
tab3.setIndicator(TAB3);
Intent Intent3 = new Intent(this, Tab3.class);
tab1.setContent(Intent3);
tabHost.addTab(tab1);
tabHost.addTab(tab2);
tabHost.addTab(tab3);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="64dp" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
Then three classes Tab1.java , Tab2.java and Tab3.java
And three xml files to that classes.
try it out and say.
When you are moving to a new activity you are building a whole new view which means that the view you where just on gets thrown out and replaced with this new one. If you want the tab bar you need to build it into this new activity like you did for the first activity.

how style tabactivity in android

Hi im trying to style my tabactivity im using this:
public class TabContainer extends TabActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab_container);
//TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
TabHost tabHost = getTabHost();
// Tab for Radio
TabSpec radioTabSpec = tabHost.newTabSpec("Radio Online");
// setting Title and Icon for the Tab
radioTabSpec.setIndicator("Radio Online", getResources().getDrawable(R.drawable.menu_radio));
Intent radioIntent = new Intent(this, MainActivity.class);
radioTabSpec.setContent(radioIntent);
// Tab for Facebook
TabSpec facebookTabSpec = tabHost.newTabSpec("Facebook");
facebookTabSpec.setIndicator("Facebook", getResources().getDrawable(R.drawable.menu_facebook));
Intent facebookIntent = new Intent(this, FacebookActivity.class);
facebookTabSpec.setContent(facebookIntent);
// Tab for Twitter
TabSpec twitterTabSpec = tabHost.newTabSpec("Twitter");
twitterTabSpec.setIndicator("Twitter", getResources().getDrawable(R.drawable.menu_twitter));
Intent twitterIntent = new Intent(this, TwitterActivity.class);
twitterTabSpec.setContent(twitterIntent);
// Tab for About
TabSpec aboutTabSpec = tabHost.newTabSpec("Acerca");
aboutTabSpec.setIndicator("Acerca", getResources().getDrawable(R.drawable.menu_about));
Intent aboutIntent = new Intent(this, AboutActivity.class);
aboutTabSpec.setContent(aboutIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(radioTabSpec); // Adding photos tab
tabHost.addTab(facebookTabSpec); // Adding songs tab
tabHost.addTab(twitterTabSpec); // Adding videos tab
tabHost.addTab(aboutTabSpec); // Adding videos tab
}
}
here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</TabHost>
tabs style example:
i know tabactivity is old but i cant find any other way to make it work for android 2.3 and later now my tabs are showing totally black, i would like to style it to make it more nice.
thank you very much.
Why cant you use fragments.To support in all versions, use Action bar Sherlock library
http://wptrafficanalyzer.in/blog/adding-navigation-tabs-containing-listview-to-action-bar-in-pre-honeycomb-versions-using-sherlock-library/
FYI TabActivity is deprecated.
Instead, why don't you use ActionBar with tabs and to provide compatibility, you can use ActionBarSherlock.
What is ActionBarSherlock?
ActionBarSherlock is an extension of the support library designed to
facilitate the use of the action bar design pattern across all
versions of Android with a single API.

tab doesnot show tab name in ginger bread

I am developing an application that uses tabs.
The problen is: in devices with API level 15 or higher it is working fine, but in lower than API 15 (for ex GingerBread) it is not working.
Problem: In tabs, it dosenot show the text that I have written on tabs, it just show blank tabs.
You can see the images
correct image : we can see the tab names "Tracker"," Call Logs", "STD codes" and "ISD Codes"
Problem Image tab name not shown in this image(in gingerbread)
As you can see in this image tab names names are not shown.
My code is below
main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:id="#android:id/tabhost"
>
<TabWidget
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#android:id/tabs"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#android:id/tabcontent"
>
</FrameLayout>
</LinearLayout>
</TabHost>
My activity file is
public class MobileNumberTrackerTabbedHomeActivity extends TabActivity {
/** Called when the activity is first created. */
TabHost tabHost;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost=getTabHost();
//First Tab
TabSpec tab1=tabHost.newTabSpec("Tracker");
tab1=tab1.setIndicator("Tracker");
Intent intentNumberTracker =new Intent(this, NumberTrackerActivity.class);
tab1=tab1.setContent(intentNumberTracker);
TabSpec tab2=tabHost.newTabSpec("STD Codes");
tab2=tab2.setIndicator("STD Codes");
Intent intentSTDCode=new Intent(this,STDCodeFinderActivity.class);
tab2=tab2.setContent(intentSTDCode);
TabSpec tab3=tabHost.newTabSpec("ISD Codes");
tab3=tab3.setIndicator("ISD Codes");
Intent intentISDCode=new Intent(this,ISDCodeFinderActivity.class);
tab3=tab3.setContent(intentISDCode);
TabSpec tab4=tabHost.newTabSpec("Call Logs");
tab4=tab4.setIndicator("Call Logs");
Intent intenCallLogs=new Intent(this,ShowCallLogsActivity.class);
tab4=tab4.setContent(intenCallLogs);
tabHost.addTab(tab1);
tabHost.addTab(tab4);
tabHost.addTab(tab2);
tabHost.addTab(tab3);
}
}
What should I do so that tabs worh fine with all APIs
Please suggest a solution
thanks
It should be like,
//First Tab
TabSpec tab1=tabHost.newTabSpec("Tracker");
tab1.setIndicator("Tracker");
Intent intentNumberTracker =new Intent(this, NumberTrackerActivity.class);
tab1.setContent(intentNumberTracker);
for each Tab, instead of
//First Tab
TabSpec tab1=tabHost.newTabSpec("Tracker");
tab1=tab1.setIndicator("Tracker");
Intent intentNumberTracker =new Intent(this, NumberTrackerActivity.class);
tab1=tab1.setContent(intentNumberTracker);
By assigning everytime tab1 = new content/setting you are over-writing the previous set fields.

Exception with Tabs: "you must specify a way to create tab indicator"

My application consists three tabs and two of them have the ListView and one is just activity with TextView. To get main activity with Tabs I use the example from developers.anroid.com http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
According to this example my layout is:
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#android:id/tabhost"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
</TabHost>
So, next code is code of activity (there are only two pages):
public class MainActivity extends TabActivity {
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs_layout_start_page);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent(this, ListViewTab1Activity.class);
spec = tabHost.newTabSpec("Page1").setIndicator("Page 1", res.getDrawable(R.drawable.icon))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent(this, ListViewTab2Activity.class);
spec = tabHost.newTabSpec("Page 2").setIndicator("Page 2", res.getDrawable(R.drawable.icon))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(1);
}
}
Every intent is pointed to another activity, which has hard-coded ListView in layout and code to define it from string-array from resources. But after starting I get exception
IllegalArgument Exception ""you must specify a way to create tab indicator". and it makes me stopped, please, help me.
thanks for everyone
Intent i;
i = new Intent().setClass(this, Tab1.class);
TabSpec sp = th.newTabSpec("Tab1");
sp.setIndicator("alma");
sp.setContent(i);
th.addTab(sp);
i = new Intent().setClass(this, Tab2.class);
sp = th.newTabSpec("Tab2");
sp.setIndicator("alma2");
th.addTab(sp);
th.setCurrentTab(0);
This code is works perfectly, so you should try to make
this
spec = tabHost.newTabSpec("Page 2").setIndicator("Page 2", res.getDrawable(R.drawable.icon))
get separated as I had done. Maybe shoudn`t use single command line to set attrs.
I just had this same problem.
I found my problem was the reuse of sp
I did this to solve the problem:
TabSpec spec1=tabHost.newTabSpec("Tab 1");
spec1.setContent(R.id.tab1);
spec1.setIndicator("Tab 1",getResources().getDrawable(R.drawable.icon_tab1_config));
TabSpec spec2=tabHost.newTabSpec("Tab 2");
spec2.setIndicator("Tab 2",getResources().getDrawable(R.drawable.icon_tab2_config));
spec2.setContent(R.id.tab2);
using different TabSpec values fixed the issue for me.

Categories

Resources