如何在freamelayout上实现recyclerview?

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

我正在学习recyclerview并被卡住。在活动中,我具有bottomnavigationview,并且在bottomnavigationview上方有框架布局。我想在该framelayout上显示recyclerview。我该怎么做?我的程序中没有错误。而且我不知道为什么它没有显示recyclerview。这是xml

<RelativeLayout
    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=".Bottom_nav">

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/bottomnavid"
       />
    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottomnavid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:menu="@menu/bottom_nav"
        />
</RelativeLayout>


this is the recyclerview
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="#FFEB3B"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/live_matchrecyclerid"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</FrameLayout>

cardview xml 

    <android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="10dp"
    android:padding="5dp"
    app:cardCornerRadius="3dp"
    app:cardElevation="5dp"
    >


    <TextView
        android:id="@+id/cityid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Hello"
        android:textSize="50sp"
        android:padding="5dp"/>

</android.support.v7.widget.CardView>

this is the myadapter class

    public class Myadapter extends RecyclerView.Adapter<Myviewholder> {
        ArrayList<String> Citynames;
        Context c;
         public Myadapter(ArrayList<String> citynames, Context c) {
        Citynames = citynames;
        this.c = c;
    }
    @NonNull
    @Override
    public Myviewholder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(c).inflate(R.layout.cardview,viewGroup,false);
        Myviewholder VH = new Myviewholder(v);
        return VH;
    }
    @Override
    public void onBindViewHolder(@NonNull Myviewholder myviewholder, int i) {
        myviewholder.nametext.setText(Citynames.get(i));
    }
    @Override
    public int getItemCount() {
        return Citynames.size();
    }
}
this is my viewholder class 
    public class Myviewholder extends RecyclerView.ViewHolder {

    TextView nametext;

    public Myviewholder(@NonNull View itemView) {
        super(itemView);
        nametext = itemView.findViewById(R.id.cityid);
    }
}

this is my main class

    public class Feature extends Fragment {
       ArrayList<String> Citynames = new ArrayList<>   (Arrays.asList("dhaka","rongpur","bagura",
            "sylhet","vhola","lalmonirhut","khulna","cumillah","rajshahi"));
    public  Feature()
    {

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view  = inflater.inflate(R.layout.feature,container,false);

         RecyclerView recyclerView = view.findViewById(R.id.featurerecyclerid);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        Myadapter myadapter = new Myadapter(Citynames,getActivity());
        recyclerView.setAdapter(myadapter);
        return inflater.inflate(R.layout.feature,container,false);
    }
}

没有错误显示在我的项目中,但没有显示recyclerview。

android-recyclerview fragment android-framelayout bottomnavigationview
1个回答
0
投票

好的,您只需在创建碎片视图之前设置您的回收站视图,我主要是在您的上一个问题中提及您在“ onViewCreated”方法中设置您的Recyler视图,在此处查看我的答案。不要一次又一次发布相同的问题,也可以编辑问题

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