Ich habe ein TabWidget mit einigen Fragment drin. Ich möchte eine ProgressBar darin anzeigen, aber die ProgressBar wird nie angezeigt. Hier ist mein Code:ProgressBar Programmatisch in Fragment
private ProgressBar progressBar;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.roomstatusadmin_activity, container, false);
progressBar = new ProgressBar(getActivity().getApplicationContext(), null, android.R.attr.progressBarStyleSmall);
progressBar.setIndeterminate(true);
progressBar.setVisibility(View.VISIBLE);
//FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//layoutParams.gravity = Gravity.CENTER;
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
progressBar.setLayoutParams(layoutParams);
return view;
}
las ich einige Frage, aber es gibt keine Lösung, wie this. Ich teste mit Hinzufügen der ProgressBar in meine layout.xml und die ProgressBar wird angezeigt. Aber ich werde diese ProgressBar in irgendeinem Layout verwenden, also brauche ich es wirklich programmatisch. Danke im Voraus.
Entfernen 'getApplicationContext()' –