Android Spinner SetAdapter隐藏进度条

时间:2019-04-16 10:09:12

标签: java android progress-bar android-spinner android-adapter

我不知道为什么,但是当我为我的适配器调用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。如果我坚持下去,我看不到进度。视图具有白色背景,仅在加载数据时填充列表。我如何才能看到ProgressBar并设置微调器的适配器而不会出现此问题?

0 个答案:

没有答案
相关问题