使用选项卡中的ActivityGroup切换活动(Android)

时间:2011-04-26 12:36:01

标签: android tabs activitygroup

在活动之间的转换中(使用选项卡中的ActivityGroup)错误:

04-26 08:46:04.599: ERROR/AndroidRuntime(992): java.lang.StackOverflowError
04-26 08:46:04.599: ERROR/AndroidRuntime(992): at android.text.Layout.measureText(Layout.java:1601)
04-26 08:46:04.599: ERROR/AndroidRuntime(992): at android.text.Layout.getLineMax(Layout.java:655)
04-26 08:46:04.599: ERROR/AndroidRuntime(992): at android.text.Layout.draw(Layout.java:311)
04-26 08:46:04.599: ERROR/AndroidRuntime(992): at android.text.BoringLayout.draw(BoringLayout.java:365)
04-26 08:46:04.599: ERROR/AndroidRuntime(992): at android.widget.TextView.onDraw(TextView.java:4052)
04-26 08:46:04.599: ERROR/AndroidRuntime(992): at android.view.View.draw(View.java:6535)
04-26 08:46:04.599: ERROR/AndroidRuntime(992): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
04-26 08:46:04.599: ERROR/AndroidRuntime(992): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
...

代码:

    ...
private ListView _lv;
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
List cats = Category.getAllCategories(this);
_lv = (ListView)findViewById(android.R.id.list);
_lv.setAdapter(new CategoryAdapter(getBaseContext(),R.layout.list_item_layout, cats));
_lv.setOnItemClickListener(new ListClickListener());
...
}
public void replaceContentView(String id, Intent newIntent/*,int result*/) {
View view = getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
this.setContentView(view);
}

代码来自此处:www.gamma-point.com/content/android-how-have-multiple-activities-under-single-tab-tabactivity

我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/recipes_in_cat_list"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <LinearLayout
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:gravity="left"
   android:background="@drawable/tab_upper_bar">
   <Button
    android:id="@+id/back_to_cats_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dip"
    android:background="@drawable/android_info_button" />

    <ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:divider = "#00000000"
    android:cacheColorHint="#00000000" />

列表项的布局:

<?xml version=«1.0» encoding=«utf-8»?>
<LinearLayout
xmlns:android=«schemas.android.com/apk/res/android»
android:orientation=«horizontal»
android:layout_width=«fill_parent»
android:layout_height=«40dip»
android:layout_weight=«1»
android:padding = «10dip»
android:background ="@drawable/list_item_bg"
android:layout_centerHorizontal=«true»>
<ImageView
 android:id="@+id/recipe_list_left"
 android:layout_width=«wrap_content»
 android:layout_height=«fill_parent»
 android:src="@drawable/list_left"
 android:layout_weight=«0» />
 <TextView
  android:id="@+id/recipe_list_text"
  android:layout_width=«fill_parent»
  android:layout_height=«fill_parent»
  style = "@style/RecipeListText"
  android:layout_weight=«1»
  android:gravity=«center_horizontal» />
 <ImageView
  android:id="@+id/recipe_list_right"
  android:layout_width=«wrap_content»
  android:layout_height=«fill_parent»
  android:src="@drawable/list_right"
  android:layout_weight=«0» />

谁遇到此错误? 请帮忙

1 个答案:

答案 0 :(得分:1)

StackOverflow异常通常意味着您处于无限循环中,并且调用堆栈最终溢出。你能展示更多的堆栈跟踪吗?事实上,当onOptionsItemSelected()自己调用它时(无意中很明显),我在今天发生了这种情况。