Android Scrollview中的Tablelayout不工作

Android Scrollview中的Tablelayout不工作,android,scrollview,android-3.0-honeycomb,tablelayout,Android,Scrollview,Android 3.0 Honeycomb,Tablelayout,我的片段将其数据加载到scrollview中的tablelayout中。首先,它将加载“单击图像查看更多数据”字样。 我有一个来自图库的onclick侦听器,它应该使用tablelayout.removeallview()删除tablelayout中的所有行。然后,片段将向scrollview内的tablelayout添加行 每次单击gallery时,tablelayout都应该更改 但是我得到:**java.lang.IllegalStateException:ScrollView只能承载一个

我的片段将其数据加载到scrollview中的tablelayout中。首先,它将加载“单击图像查看更多数据”字样。
我有一个来自图库的onclick侦听器,它应该使用
tablelayout.removeallview()删除tablelayout中的所有行。然后,片段将向scrollview内的tablelayout添加行

每次单击gallery时,tablelayout都应该更改

但是我得到:**java.lang.IllegalStateException:ScrollView只能承载一个直接子级。 此行在logcat中显示上述错误:
getFragmentManager().executePendingTransactions()在我的addToTracker函数中

画廊活动

public class GalleryActivity extends Activity 
{
    private  Gallery[] galleryView;
    private ArrayList<ArrayList<Dish>> listOfList;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        galleryView = new Gallery[3];

        //for each of the 3 sites
        galleryView[0] = (Gallery)findViewById(R.id.galleryid0);
        galleryView[1] = (Gallery)findViewById(R.id.galleryid1);
        galleryView[2] = (Gallery)findViewById(R.id.galleryid2);

        final FragmentManager fragmentManager = getFragmentManager();
        final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        galleryView[0].setOnItemClickListener(new OnItemClickListener() 
        {
            public void onItemClick(AdapterView parent, View v, int position, long id) 
            {
                addToTracker(0, position, fragmentTransaction);
            }
        });

        galleryView[1].setOnItemClickListener(new OnItemClickListener() 
        {
            public void onItemClick(AdapterView parent, View v, int position, long id) 
            {
                addToTracker(1, position, fragmentTransaction);
            }
        });

        galleryView[2].setOnItemClickListener(new OnItemClickListener() 
        {
            public void onItemClick(AdapterView parent, View v, int position, long id) 
            {
                addToTracker(2, position, fragmentTransaction);
            }
        });
    }

    private void addToTracker(int id, int position, FragmentTransaction fragmentTransaction)
    {
            TrackerFragment tf = (TrackerFragment) getFragmentManager().findFragmentById(R.id.tracker1);
            fragmentTransaction.remove(tf);
            tf = TrackerFragment.newInstance(listOfList.get(id).get(position));

            fragmentTransaction.replace(R.id.tracker1, tf);
            fragmentTransaction.commitAllowingStateLoss();
            getFragmentManager().executePendingTransactions();
   }
公共类GalleryActivity扩展活动
{
私人画廊[]galleryView;
私有数组列表;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
galleryView=新画廊[3];
//对于3个站点中的每个站点
galleryView[0]=(Gallery)findViewById(R.id.galleryid0);
galleryView[1]=(画廊)findViewById(R.id.GalleryD1);
galleryView[2]=(画廊)findViewById(R.id.galleryid2);
final FragmentManager FragmentManager=getFragmentManager();
final FragmentTransaction FragmentTransaction=fragmentManager.beginTransaction();
galleryView[0]。setOnItemClickListener(新的OnItemClickListener()
{
public void onItemClick(AdapterView父视图、视图v、整型位置、长id)
{
addToTracker(0,位置,碎片事务);
}
});
galleryView[1]。setOnItemClickListener(新的OnItemClickListener()
{
public void onItemClick(AdapterView父视图、视图v、整型位置、长id)
{
addToTracker(1,位置,碎片交易);
}
});
galleryView[2]。setOnItemClickListener(新的OnItemClickListener()
{
public void onItemClick(AdapterView父视图、视图v、整型位置、长id)
{
addToTracker(2,位置,碎片交易);
}
});
}
私有void addToTracker(整数id、整数位置、碎片事务碎片事务)
{
TrackerFragment tf=(TrackerFragment)getFragmentManager().findFragmentById(R.id.tracker1);
碎片事务。删除(tf);
tf=TrackerFragment.newInstance(listOfList.get(id.get(position));
fragmentTransaction.replace(R.id.tracker1,tf);
fragmentTransaction.commitAllowingStateLoss();
getFragmentManager().executePendingTransactions();
}
跟踪器碎片

public class TrackerFragment extends Fragment
{
    private Dish dish;

    public static TrackerFragment newInstance(Serializable dish) 
    {
        TrackerFragment tf = new TrackerFragment();

        Bundle args = new Bundle();
        args.putSerializable("dish", dish);
        tf.setArguments(args);

        return tf;
    }

    public static TrackerFragment newInstance(Bundle bundle)
    {
        Dish dish = (Dish) bundle.getSerializable("dish");
        return newInstance(dish);
    }

    @Override
    public void onCreate(Bundle myBundle)
    {
        super.onCreate(myBundle);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) 
    {
        View v = inflater.inflate(R.layout.tracker, container, false);

        TableLayout tableLayout = (TableLayout) v.findViewById(R.id.tracker_layout);
        tableLayout.removeAllViews();

        if (dish != null)
        {   
            //display others

            //display subsystem stuff
            for (int i = 0; i < dish.getSubsystems().size(); i++)
            {
                TableRow tableRow = new TableRow(v.getContext());
                tableRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));

                TextView tv = new TextView(v.getContext());
                tv.setText(dish.getSubsystems().get(i).getConnFuncAddr());

                tableRow.addView(tv);

                tableLayout.addView(tableRow);
            }
        }
        else
        {
            TableRow tableRow = new TableRow(v.getContext());
            tableRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));

            TextView tv = new TextView(v.getContext());
            tv.setText("Click on image to view more data");

            tableRow.addView(tv);

            tableLayout.addView(tableRow);
        }

        return v;
    }
}
公共类TrackerFragment扩展片段
{
私家菜;
公共静态TrackerFragment newInstance(可序列化的碟形盘)
{
TrackerFragment tf=新TrackerFragment();
Bundle args=新Bundle();
args.putSerializable(“dish”,dish);
tf.setArguments(args);
返回tf;
}
公共静态TrackerFragment newInstance(捆绑包)
{
Dish Dish=(Dish)bundle.getSerializable(“Dish”);
返回新实例(dish);
}
@凌驾
创建公共void(Bundle myBundle)
{
super.onCreate(myBundle);
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState)
{
视图v=充气机。充气(R.layout.tracker,容器,假);
TableLayout TableLayout=(TableLayout)v.findViewById(R.id.tracker\u布局);
tableLayout.removeallview();
if(dish!=null)
{   
//展示他人
//显示子系统材料
对于(int i=0;i
main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Trackers -->
    <LinearLayout
        android:layout_height="fill_parent"
        android:layout_width="300dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <fragment 
            android:name="android.gallery.TrackerFragment"
            android:id="@+id/tracker1"
            android:layout_height="500dp"
            android:layout_width="300dp"
            android:layout_weight="1">
        </fragment>

    </LinearLayout>

    <!-- Gallery -->
    <LinearLayout
        android:layout_height="fill_parent"
        android:layout_width="600dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="245dp">

            <Gallery 
                android:id="@+id/galleryid0"
                android:layout_width="fill_parent" 
                android:layout_height="match_parent"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="245dp">

            <Gallery 
                android:id="@+id/galleryid1"
                android:layout_width="fill_parent" 
                android:layout_height="match_parent"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="245dp">

            <Gallery 
                android:id="@+id/galleryid2"
                android:layout_width="fill_parent" 
                android:layout_height="match_parent"/>

            </LinearLayout>

        </LinearLayout>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" >

      <TextView 
        android:layout_height="wrap_content"
        android:layout_width="250dp"
        android:text="Tracker 1" 
        android:id="@+id/t1"/>

      <ImageButton
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:src="@drawable/delete2"
        android:onClick="remove1"
        android:layout_toRightOf="@id/t1" />

      <TableLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:id="@+id/tracker_layout"
        android:layout_below="@id/t1"
        android:layout_marginTop="40dp">    

      </TableLayout>

    </RelativeLayout>

</ScrollView>

tracker.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Trackers -->
    <LinearLayout
        android:layout_height="fill_parent"
        android:layout_width="300dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <fragment 
            android:name="android.gallery.TrackerFragment"
            android:id="@+id/tracker1"
            android:layout_height="500dp"
            android:layout_width="300dp"
            android:layout_weight="1">
        </fragment>

    </LinearLayout>

    <!-- Gallery -->
    <LinearLayout
        android:layout_height="fill_parent"
        android:layout_width="600dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="245dp">

            <Gallery 
                android:id="@+id/galleryid0"
                android:layout_width="fill_parent" 
                android:layout_height="match_parent"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="245dp">

            <Gallery 
                android:id="@+id/galleryid1"
                android:layout_width="fill_parent" 
                android:layout_height="match_parent"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="245dp">

            <Gallery 
                android:id="@+id/galleryid2"
                android:layout_width="fill_parent" 
                android:layout_height="match_parent"/>

            </LinearLayout>

        </LinearLayout>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" >

      <TextView 
        android:layout_height="wrap_content"
        android:layout_width="250dp"
        android:text="Tracker 1" 
        android:id="@+id/t1"/>

      <ImageButton
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:src="@drawable/delete2"
        android:onClick="remove1"
        android:layout_toRightOf="@id/t1" />

      <TableLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:id="@+id/tracker_layout"
        android:layout_below="@id/t1"
        android:layout_marginTop="40dp">    

      </TableLayout>

    </RelativeLayout>

</ScrollView>

有人知道怎么回事吗?我猜我是在向scrollview中添加一个表行,而不是在tablelayout中,但是,我看不出我在代码中犯了什么错误。

以这种方式创建Tablelaout
 Create Tablelaout in this way




<?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent">



      <TableLayout
            android:id="@+id/data_table"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            >
  </TableLayout>
    </ScrollView>
以这种方式创建Tablelaout

我仍然得到
java.lang.IllegalStateException:ScrollView只能承载一个直接子项
。此行还得到一个错误:
getFragmentManager().executePendingTransactions();
我仍然得到
java.lang.IllegalStateException:ScrollView只能承载一个直接子项
。此行还得到一个错误:
getFragmentManager().executePendingTransactions();