Source code :
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TabHost
android:id="@+id/th_settings_menu_tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="@android:id/tabs"
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"
>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
android:layout_weight="1"
>
<!-- Page 3 -->
<LinearLayout
android:id="@+id/log"
android:paddingTop="20px"
android:orientation="vertical"
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:layout_weight="1">
<TextView
android:id="@+id/timecosts"
android:text="@string/showtime"
android:layout_width="fill_parent"
android:layout_height="120px"
android:textSize="59px"
android:gravity="center"
></TextView>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:layout_weight="1">
<Button
android:id="@+id/start"
android:layout_width="fill_parent"
android:layout_height="180px"
android:text="@string/start"
android:textSize="35px"
android:background ="@drawable/button_green"
android:focusable="true"
/>
</LinearLayout>
</LinearLayout>
<!-- Page 2 -->
<LinearLayout
android:paddingTop="20px"
android:id="@+id/settings"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<CheckBox
android:id="@+id/autostart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/autostart"
android:textSize="20px"
>
</CheckBox>
<TextView
android:id="@+id/logsize_txt"
android:text="@string/logsize_in"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20px"
></TextView>
<Spinner
android:id="@+id/logsize"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</Spinner>
<TextView
android:id="@+id/logmask_txt"
android:text="@string/logmasks"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20px"
></TextView>
<Spinner
android:id="@+id/logmask"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</Spinner>
</LinearLayout>
<!-- Page 1 -->
<LinearLayout
android:id="@+id/records"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@android:id/list"
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
</ListView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
src code:
public class aa extends ListActivity {
protected TabHost myTabHost;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.myTabHost = (TabHost) this
.findViewById(R.id.th_settings_menu_tabhost);
this.setupTabs();
myTabHost.setOnTabChangedListener(changeListener);
}
private void setupTabs() {
this.myTabHost.setup();
TabSpec logging = this.myTabHost
.newTabSpec("A");
logging.setIndicator(getResources().getString(R.string.log),
getResources().getDrawable(R.drawable.log));
logging.setContent(R.id.log);
this.myTabHost.addTab(logging);
TabSpec settings = this.myTabHost
.newTabSpec("B");
settings.setIndicator(getResources().getString(R.string.setting),
getResources().getDrawable(R.drawable.setting));
settings.setContent(R.id.settings);
this.myTabHost.addTab(settings);
TabSpec records = this.myTabHost
.newTabSpec("C");
records.setIndicator(getResources().getString(R.string.records),
getResources().getDrawable(R.drawable.order_info));
records.setContent(R.id.records);
this.myTabHost.addTab(records);
this.myTabHost.setCurrentTab(0);
}
OnTabChangeListener changeListener = new OnTabChangeListener(){
@Override
public void onTabChanged(String tabId) {
setTitle(tabId);
}
};
@Override
protected void onStart(){
super.onStart();
Log.i("TestService","onStart");
}
@Override
protected void onDestroy(){
super.onDestroy();
finish();
}
@Override
protected void onPause() {
super.onPause();
Log.i("TestService","onPause");
}
@Override
protected void onResume() {
super.onResume();
Log.i("TestService","onResume");
}
}
This test apk run fine on emulator android2.3.1,android3.0,but force
close when launching on one android2.3.1 real phone.
Log is:
I/ActivityManager( 207): Start proc com.aa for activity com.aa/.aa:
pid=2159 uid=1000 gids={1007, 3002, 3003, 3001, 2001,
1015}
E/dalvikvm( 2159): could not disable core file generation for pid
2159: Operatio
n not permitted
I/TestService( 2159): onCreate....
I/TestService( 2159): onStart...
I/TestService( 2159): onResume...
D/AndroidRuntime( 2159): Shutting down VM
W/dalvikvm( 2159): threadid=1: thread exiting with uncaught exception
(group=0x4
0018560)
E/AndroidRuntime( 2159): FATAL EXCEPTION: main
E/AndroidRuntime( 2159): java.lang.ClassCastException:
android.widget.LinearLayo
ut$LayoutParams
E/AndroidRuntime( 2159): at
android.widget.FrameLayout.onLayout(FrameLayo
ut.java:293)
E/AndroidRuntime( 2159): at android.view.View.layout(View.java:
7184)
E/AndroidRuntime( 2159): at
android.widget.LinearLayout.setChildFrame(Lin
earLayout.java:1254)
E/AndroidRuntime( 2159): at
android.widget.LinearLayout.layoutVertical(Li
nearLayout.java:1130)
E/AndroidRuntime( 2159): at
android.widget.LinearLayout.onLayout(LinearLa
yout.java:1047)
E/AndroidRuntime( 2159): at android.view.View.layout(View.java:
7184)
E/AndroidRuntime( 2159): at
android.widget.FrameLayout.onLayout(FrameLayo
ut.java:338)
E/AndroidRuntime( 2159): at android.view.View.layout(View.java:
7184)
E/AndroidRuntime( 2159): at
android.widget.LinearLayout.setChildFrame(Lin
earLayout.java:1254)
E/AndroidRuntime( 2159): at
android.widget.LinearLayout.layoutVertical(Li
nearLayout.java:1130)
E/AndroidRuntime( 2159): at
android.widget.LinearLayout.onLayout(LinearLa
yout.java:1047)
E/AndroidRuntime( 2159): at android.view.View.layout(View.java:
7184)
E/AndroidRuntime( 2159): at
android.widget.FrameLayout.onLayout(FrameLayo
ut.java:338)
E/AndroidRuntime( 2159): at android.view.View.layout(View.java:
7184)
E/AndroidRuntime( 2159): at
android.view.ViewRoot.performTraversals(ViewR
oot.java:1140)
E/AndroidRuntime( 2159): at
android.view.ViewRoot.handleMessage(ViewRoot.
java:1859)
E/AndroidRuntime( 2159): at
android.os.Handler.dispatchMessage(Handler.ja
va:99)
E/AndroidRuntime( 2159): at android.os.Looper.loop(Looper.java:
123)
E/AndroidRuntime( 2159): at
android.app.ActivityThread.main(ActivityThrea
d.java:3785)
E/AndroidRuntime( 2159): at
java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime( 2159): at
java.lang.reflect.Method.invoke(Method.java:5
07)
E/AndroidRuntime( 2159): at com.android.internal.os.ZygoteInit
$MethodAndA
rgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 2159): at
com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:597)
E/AndroidRuntime( 2159): at
dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 207): Force finishing activity com.aa/.aa
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en