0

データベースからデータをロードするアクティビティがあり、データセットごとに行に入れられます。データの各セットには、家事、ゲーム、スポーツなどの 1 つのカテゴリがあります。

4 つの TableLayout があり、グループ名を比較する "if" 条件を使用して、データのセットを適切な TableLayout に拡張したいと考えています。

質問:

TableLayout にインフレートされるものはありません。それでも、トーストは膨張するたびに正しく表示され、余分なスペースがないことを示す XHouseworksX などを出力します。行が膨張していないのはなぜですか???

さらに詳しい情報:

すべての if 句を削除し、TableLayout のいずれか 1 つだけに膨張させると、ビューを適切に膨張させることができます。

以下のようにコーディングの詳細:

主な活動

//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 に答える