I'm trying to make a list of checkboxes dynamically and I need these checkboxes to be in a ScrollView. I've managed to add the checkboxes dynamically, but it won't scroll even when there are a lot of checkboxes. This is the ScrollView:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/payersLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
And this is the code that adds the checkboxes dynamically:
// sets up the payee checkboxes
LinearLayout payersLinearLayout = (LinearLayout) findViewById(R.id.payersLinearLayout);
participants.add("Test 1");
participants.add("Test 2");
participants.add("Test 3");
participants.add("Test 4");
participants.add("Test 5");
participants.add("Test 6");
participants.add("Test 7");
participants.add("Test 8");
int participantsSize = participants.size();
for (int i = 0; i < participantsSize; i++) {
LinearLayout payerLinearLayout = new LinearLayout(this);
payerLinearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
payerLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,
1.0f
);
CheckBox checkBox = new CheckBox(this);
checkBox.setId(i);
checkBox.setText(participants.get(i));
checkBox.setLayoutParams(param);
EditText editText = new EditText(this);
editText.setText("0.00");
editText.setLayoutParams(param);
payerLinearLayout.addView(checkBox);
payerLinearLayout.addView(editText);
payersLinearLayout.addView(payerLinearLayout);
}
I'm not sure what the problem is and why it won't scroll. I'm not sure if it's relevant, but the ScrollView itself is in a Linear Layout, which is also in a Linear Layout, which is in an App Bar Layout. Could anybody help? Any help would be appreciated!