Add A ProgressBar Programatically To A Fragment In Android
I was able to manipulate some text of an existing TextView in a Fragment. However I was not able to programatically add a new ProgressBar to the existing layout. In the Fragment cl
Solution 1:
It is not showing because you did not specify its child's layout_param and therefore will result to parent not displaying it.
You need to specify the layout params of the child view you want to attach.
progressBar = new ProgressBar(this.getContext());
progressBar.setMax(daysInTotal);
progressBar.setProgress(daysCompleted);
progressBar.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
Solution 2:
You have specified "linearLayoutCompletedOfficeHours" as a Linear Layout with android:orientation="horizontal"
and given textview android:layout_width="match_parent"
.Making this will make textview to take entire space and progressbar is created and shown in the screen.
Instead change textView width to android:layout_width="wrap_content"
and the progress will be visible.
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/completedXOfYDays" />
Post a Comment for "Add A ProgressBar Programatically To A Fragment In Android"