Мне удалось манипулировать текстом существующего TextView во фрагменте. Однако я не смог программно добавить новый ProgressBar
в существующий макет.
В классе Фрагмент:Добавить ProgressBar программно к фрагменту в Android
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_completed_office_hours, container, false);
LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.linearLayoutCompletedOfficeHours);
progressBar = new ProgressBar(this.getContext());
progressBar.setMax(daysInTotal);
progressBar.setProgress(daysCompleted);
linearLayout.addView(progressBar);
TextView textView = (TextView) view.findViewById(R.id.completedXOfYDays);
textView.setText(daysCompleted + "/" + daysInTotal);
return view;
}
XML-:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragment.CompletedOfficeHoursFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_horizontal_margin"
android:orientation="horizontal"
android:id="@+id/linearLayoutCompletedOfficeHours">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/completedXOfYDays" />
</LinearLayout>
</FrameLayout>
При выполнении его я получаю 19/299
как текст, но без каких-либо ProgressBar
. Что я делаю неправильно =
К сожалению, это не решает проблему –