Я не знаю почему, но когда я вызываю метод setAdapter для моего адаптера, остальная часть представления исчезает.Я собираюсь объяснить, что я имею в виду.Это мое мнение
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/day_filter"
android:gravity="center"
android:textSize="17sp"
android:text="Text"
android:layout_weight="1"
android:background="@color/btnBgColor"
android:layout_marginRight="2dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/btnBgColor">
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:dropDownWidth="match_parent"
android:spinnerMode="dialog"
android:id="@+id/filterSpinner"
/>
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/myList"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorPrimary"
/>
<RelativeLayout
android:id="@+id/list_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</FrameLayout>
Что мне просто, покажите ProgressBar и скройте RecyclerView во время загрузки данных.Странно то, что это работает хорошо, если я не вызываю метод setAdapter
.У меня есть этот метод, чтобы сделать то, что мне нужно
@Override
public void showHideIfLoading(boolean loading) {
myList.setVisibility(loading ? View.INVISIBLE : View.VISIBLE);
myProgress.setVisibility(loading ? View.VISIBLE : View.INVISIBLE);
}
Я вызываю этот метод перед загрузкой данных таким образом
showHideIfLoading(true)
viewModel.getList().observe(this, new Observer<List<User>>() {
@Override
public void onChanged(@Nullable final List<User> user) {
if (users != null) {
dataLoaded(users);
}
}
});
Внутри dataLoaded()
Я звоню showHideIfLoading(false)
Конечно, все работаетхорошо, но у меня есть счетчик, и мне нужно заполнить его и установить адаптер.Итак, это то, что я написал до сих пор
filterValues.add(getResources().getString(R.string.all_category));
filterValues.add(getResources().getString(R.string.accounting));
filterValues.add(getResources().getString(R.string.part_time));
filterValues.add(getResources().getString(R.string.hr));
filterValues.add(getResources().getString(R.string.full_time));
filterAdapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, android.R.id.text1, filterValues) {........
, а затем
filterSpinner.setAdapter(filterAdapter);
Если я прокомментирую эту строку, я вижу ProgressBar.Если я буду придерживаться линии, я не вижу прогресс.Te view имеет белый фон и просто заполняет список при загрузке данных.Как я могу увидеть ProgressBar и установить адаптер моего счетчика без этой проблемы?