0

我有一个活动可以从数据库中加载数据,这些数据被放入每组数据的行中。每组数据都有一个类别,即家务、游戏、运动或其他。

有 4 个 TableLayout,我希望使用比较组名的“if”条件将数据集膨胀到合适的 TableLayout。

问题:

没有任何东西膨胀到任何 TableLayout。然而,每次充气时 Toast 都正确显示,输出例如 XHouseworksX 表明没有多余的空间。为什么没有行被充气???

更多信息:

如果我删除所有 if 子句,并仅膨胀到任何一个 TableLayout,视图可以正确膨胀到成功!

详细编码如下:

主要活动

//declaration in OnCreate

    table_list = (LinearLayout) findViewById(R.id.table_list);
    ex_housework_List = (TableLayout) findViewById(R.id.ex_housework_List);
    ex_games_List = (TableLayout) findViewById(R.id.ex_games_List);
    ex_sports_List = (TableLayout) findViewById(R.id.ex_sports_List);
    ex_others_List = (TableLayout) findViewById(R.id.ex_others_List);

    exercises = Ex_dbHlp.get_All_Ex_Data();
    int i = exercises.size();       
    for (int j = 0; j < i; j++) 
    {
        Inflate_All_Ex_Data(j); //to inflate rows to the suitable TableLayout
    }



private void Inflate_All_Ex_Data (int index) 
{   
    if(exercises.size() > 0)
    {
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View newTagView = inflater.inflate(R.layout.exercises_info, null);

        Button exercise_id = (Button) newTagView.findViewById(R.id.exercise_id);
        Button exercise_group = (Button) newTagView.findViewById(R.id.exercise_group);
        Button exercise_name = (Button) newTagView.findViewById(R.id.exercise_name);
        Button exercise_count = (Button) newTagView.findViewById(R.id.exercise_count);

        exercise_id.setText(exercises.get(index).getId());
        exercise_group.setText(exercises.get(index).get_ex_group());
        exercise_name.setText(exercises.get(index).get_ex_name());
        exercise_count.setText(exercises.get(index).get_ex_count());    

        String group = exercise_group.getText().toString();
        Toast.makeText(getBaseContext(), "X"+group+"X", Toast.LENGTH_SHORT).show();

        if (group == "Houseworks") {ex_housework_List.addView(newTagView, index);}
        if (group == "Games") {ex_games_List.addView(newTagView, index);}
        if (group == "Sports") {ex_sports_List.addView(newTagView, index);}
        if (group == "Others") {ex_others_List.addView(newTagView, index);}

XML

    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/Table2"
        android:layout_below="@+id/view1" >

        <LinearLayout
            android:id="@+id/table_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/add"
            android:layout_margin="2dp"
            android:orientation="vertical" >

            <TableLayout
                android:id="@+id/ex_housework_List"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:background="@drawable/blue_btn" />

            <TableLayout
                android:id="@+id/ex_games_List"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:background="@drawable/green_btn" />

            <TableLayout
                android:id="@+id/ex_sports_List"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:background="@drawable/yellow_btn" />

            <TableLayout
                android:id="@+id/ex_others_List"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:background="@drawable/pink_btn" />

        </LinearLayout>
    </ScrollView>   
4

1 回答 1

2

if (group == "Houseworks")

这导致了问题。而是应该改为

group.equals("Houseworks");

其他组也一样

于 2013-07-16T16:02:41.170 回答