如何向我的recyclerview添加搜索栏?

问题描述 投票:2回答:1

这是我的MainActivity:

public class sgpa_frag extends Fragment {
    //View view;
    RecyclerView recyclerview;
    adapter_sgpa ac;


    ArrayList<POJO> sgpaArrayList;

    public sgpa_frag() {
        // Required empty public constructor
    }

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

    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_sgpa_frag, container, false);
        recyclerview= (RecyclerView) view.findViewById(R.id.rc1);
        sgpaArrayList= new ArrayList<>();
        ac= new adapter_sgpa(sgpaArrayList);
        recyclerview.setLayoutManager(new LinearLayoutManager(getContext(),RecyclerView.VERTICAL,true));
        recyclerview.setAdapter(ac);

        Fetchdata1();

        return view;
    }

    private void Fetchdata1()
    {
        dbmanager db= new dbmanager(getContext());

        Cursor cursor= db.fetch_data1();

        if (cursor!= null){

           // cursor.moveToFirst();

            while (cursor.moveToNext()){

                POJO pj= new POJO();
                pj.setSname(cursor.getString(0));
                pj.setSemester(cursor.getString(1));
                pj.setSgpa(cursor.getString(2));
                pj.setPercent(cursor.getString(3));
                pj.setSchemes(cursor.getString(4));
                sgpaArrayList.add(pj);
            }

            ac= new adapter_sgpa(sgpaArrayList);

        }


    }

}

这是我的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".drawernav.bottom_navi.recycler_view.sgpa_frag">

    <!-- TODO: Update blank fragment layout -->

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rc1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="60dp">
    </androidx.recyclerview.widget.RecyclerView>

</FrameLayout>

如何在其中添加搜索栏?如何在其中添加搜索栏?如何在其中添加搜索栏?如何在其中添加搜索栏?如何在其中添加搜索栏?如何在其中添加搜索栏?

android android-recyclerview searchbar
1个回答
0
投票

只需在RecyclerView之前添加SearchView并进行配置

© www.soinside.com 2019 - 2024. All rights reserved.