У меня есть действие, которое будет загружать данные из базы данных, которые помещаются в строки для каждого набора данных. Каждый набор данных имеет одну категорию, то есть работа по дому, игры, спорт или другие.
Есть 4 TableLayout, и я хотел бы, чтобы набор данных был раздут до подходящего TableLayout, используя условие «если», которое сравнивает имя группы.
Вопрос:
Ничто не раздувается до любого TableLayout. Тем не менее, тост отображается правильно для каждого надувания, выводя, например. 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>