使用过滤结果更新列表时,Recyclerview部分标题不可见

时间:2019-03-27 07:20:28

标签: android android-recyclerview

当我更新片段中的recyclerview列表时,节标题不会显示。我该怎么办?我已经检查了recyclerview适配器,它工作正常,问题可能出在片段中。可能是片段不知道片段更新时放在哪里。

有人可以帮我吗

这是我的片段代码

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    setRetainInstance(true);

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    mRootView = inflater.inflate(R.layout.fragment_leads, container, false);
    ButterKnife.bind(this, mRootView);
    GlowShipApplication.getAppComponent().inject(this);
    mLeadListPresenter.setView(this);
    mSysPrefs = SystemAppPreferences.getInstance(getActivity());
    mProgressBarHandler = new ProgressBarHandler(getActivity());


    if (getArguments() != null) {
        mData = getArguments().getString("fragmentName");

    }


    return mRootView;
}


@Override
public void onResume() {
    super.onResume();
    String token = mSysPrefs.getToken();

    if (ConnectionInfo.isConnectingToInternet(getActivity())) {
        // api call


        mLeadListPresenter.fetchLeadList(token);



        mAdapter.notifyDataSetChanged();
        // mProgressBarHandler.show();
        rvLeads.setVisibility(View.GONE);




    } else {
        Toast.makeText(getActivity(), getResources()
                        .getString(R.string.no_internet_connection),
                Toast.LENGTH_SHORT).show();
    }
}


@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    initComponent();


}




private void initComponent() {


    rvLeads.setLayoutManager(new LinearLayoutManager(getActivity()));
    rvLeads.setHasFixedSize(true);
    mLeadList = new ArrayList<>();
    //set data and list adapter
    mAdapter = new AdapterLeads(getActivity(), mLeadList);
    rvLeads.setAdapter(mAdapter);
    mAdapter.notifyDataSetChanged();
    mAdapter.setOnItemClickListener(new AdapterLeads.OnItemClickListener() {

        @Override
        public void onItemClick(View view, Data obj, int position) {
            mProgressBarHandler.hide();
            // need to move site survey detail
            if (position > -1) {
                Intent intent = new Intent(getActivity(), SiteSurveyStatusActivity.class);
                intent.putExtra("homeOwnerID", mAdapter.getList().get(position)
                        .getData().getHomeownerId());
                intent.putExtra("dealer_status_code",mAdapter.getList().get(position)
                        .getData().getDealerStatusCode());
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);

            }



        }
    });



}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    getActivity().getMenuInflater().inflate(R.menu.search_view_menu, menu);

    MenuItem item = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) item.getActionView();
    searchView.setOnQueryTextListener(this);

    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            startActivity(getActivity().getIntent());

            return false;
        }
    });

}





@OnClick(R.id.fab)
public void createLead(View view) {
    Intent intent = new Intent(getActivity(), LeadActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
}

@Override
public void onSuccessFetchLeadList(LeadList leadList) {
    mProgressBarHandler.hide();

    if (leadList != null) {
        rvLeads.setVisibility(View.VISIBLE);
        noRecordFoundImage.setVisibility(View.INVISIBLE);
        mLeadList.clear();


        if (mData != null) {


            if (mData.contains("proposals")) {

                View view = rvLeads.getChildAt(0);
                Log.d(TAG, "onSuccessFetchLeadList: " + view);
                ArrayList<Datum> filterdNames = new ArrayList<>();

                //looping through existing elements
                for (Datum s : leadList.getData()) {
                    //if the existing elements contains the search input
                    if (!s.getIstitle())
                        if (s.getData().getStatusId().contains("P3") ||
                                s.getData().getStatusId().contains("P4") ||
                                s.getData().getStatusId().contains("P5") ||
                                s.getData().getStatusId().contains("P6") ||
                                s.getData().getStatusId().contains("P7") ||
                                s.getData().getStatusId().contains("P8")) {
                            //adding the element to filtered list
                            filterdNames.add(s);
                            mLeadList.addAll(filterdNames);
                            Set<Datum> setList = new LinkedHashSet<>(mLeadList);
                            mLeadList.clear();
                            mLeadList.addAll(setList);
                        }


                }

            } else if (mData.contains("installations")) {
                //to be continued latter
                ArrayList<Datum> filterdNames = new ArrayList<>();

                //looping through existing elements
                for (Datum s : leadList.getData()) {
                    //if the existing elements contains the search input
                    if (!s.getIstitle())
                        if (s.getData().getStatusId().contains("S11")) {
                            //adding the element to filtered list
                            filterdNames.add(s);
                            mLeadList.addAll(filterdNames);
                            Set<Datum> setList = new LinkedHashSet<>(mLeadList);
                            mLeadList.clear();
                            mLeadList.addAll(setList);


                        } else {
                            noRecordFoundImage.setVisibility(View.VISIBLE);
                        }
                }
            } else if (mData.contains("leads")) {
                mLeadList.addAll(leadList.getData());
            }


        } else {
            mLeadList.addAll(leadList.getData());
        }
        mAdapter.notifyDataSetChanged();
    }


}


@Override
public void onError(LeadList leadList) {

    mProgressBarHandler.hide();
}


@Override
public boolean onQueryTextSubmit(String query) {
    return false;
}

@Override
public boolean onQueryTextChange(String newText) {
    List<Datum> filter = filter(mLeadList, newText);
    mAdapter.filteredList(filter);
    return false;
}


//Helper method to filter out the leads list
private List<Datum> filter(List<Datum> mLeadList, String newText) {
    //new array list that will hold the filtered data
    ArrayList<Datum> filterdNames = new ArrayList<>();

    //looping through existing elements
    for (Datum s : mLeadList) {
        //if the existing elements contains the search input
        if (!s.getIstitle())
            if (s.getData().getName().contains(newText)) {
                //adding the element to filtered list
                filterdNames.add(s);
            }
    }

    //calling a method of the adapter class and passing the filtered list
    mAdapter.filteredList(filterdNames);
    return filterdNames;
}

这是我的xml文件:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="in.thelattice.glowship.dealer.leadslist.LeadsFragment">

<android.support.v7.widget.RecyclerView
    android:id="@+id/rv_leadlist"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"
    android:scrollingCache="false" />


<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:src="@drawable/nodata"
    android:id="@+id/noRecordFoundIv"
    />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:backgroundTint="@color/appYellowColor"
    app:borderWidth="0dp"
    app:srcCompat="@drawable/ic_add_black_24dp" />

0 个答案:

没有答案