У меня есть пользовательская ViewGroup (RelativeLayout) с ProgressBar и TextView.
Я хочу, чтобы некоторое время показывал progressBar, а затем скрывал и отображал представления в моем контенте.
CustomRelative
открытый класс RelativeProgressNew extends RelativeLayout {
ProgressBar progressBar;
TextView txtEmptyData;
Activity activity;
LayoutInflater mInflater;
View v;
public RelativeProgressNew(Context context, String text) {
super(context);
mInflater = LayoutInflater.from(context);
init();
}
public RelativeProgressNew(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mInflater = LayoutInflater.from(context);
init();
}
public RelativeProgressNew(Context context, AttributeSet attrs) {
super(context, attrs);
mInflater = LayoutInflater.from(context);
init();
}
private void init() {
v = mInflater.inflate(R.layout.layout_custom, this, true);
txtEmptyData = v.findViewById(R.id.txtEmptyData);
progressBar = v.findViewById(R.id.progressBar);
}
private void finish(String text) {
v = mInflater.inflate(R.layout.layout_custom, this, true);
txtEmptyData = v.findViewById(R.id.txtEmptyData);
progressBar = v.findViewById(R.id.progressBar);
progressBar.setVisibility(GONE);
txtEmptyData.setVisibility(VISIBLE);
txtEmptyData.setText(text);
}
public void finishValidData() {
progressBar.setVisibility(GONE);
txtEmptyData.setVisibility(GONE);
}
Макет Custom
<FrameLayout android:layout_marginTop="?attr/actionBarSize"
android:id="@+id/linearProgress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="visible"
xmlns:android="http://schemas.android.com/apk/res/android">
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:id="@+id/progressBar"
android:layout_gravity="center|center_vertical|center_horizontal"
android:layout_width="48dp"
android:layout_height="48dp" />
<TextView
android:id="@+id/txtEmptyData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center"
android:gravity="center"
android:paddingEnd="20dp"
android:paddingStart="20dp"
android:text="EJEMPLO"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="visible" />
</FrameLayout>
В моем фрагменте макета у меня есть это:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.yustapps.agenda_novecientos.arq.RelativeProgressNew
android:id="@+id/relativeProgress"
android:layout_width="match_parent"
android:background="@color/window_background"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:text="EXAMPLE"
android:layout_height="match_parent" />
</com.yustapps.agenda_novecientos.arq.RelativeProgressNew>
</RelativeLayout>
Фрагмент
public class Inicio extends Fragment implements ConstantsInterface {
View v;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
v = inflater.inflate(R.layout.fragment_inicio, container, false);
relativeProgress = new RelativeProgressNew(getActivity(), ConstantsInterface.EMPTY);
simulateLoading();
return v;
}
private void simulateLoading() {
new AsyncTask<Void, Void, Void>() {
@Override
protected void onPreExecute() {
}
@Override
protected Void doInBackground(Void... params) {
try {
Thread.sleep(3300);
} catch (InterruptedException e) {
//Log.e("MainActivity", e.getMessage());
}
return null;
}
@Override
protected void onPostExecute(Void param) {
relativeProgress.finish();
}
}.execute();
}
}
А как я могу это сделать? Когда я показываю вид во фрагменте, он работает правильно, но затем я хочу скрыть прогрессбар, а фрагмент не обновляется.
Кто-нибудь может мне помочь?