【问题标题】:i used recylerview now i want when any item of recylerview is clicked then a fragment popup on full screen我现在使用了 recyclerview,我希望在单击任何 recyclerview 项目时,然后在全屏上弹出一个片段
【发布时间】:2019-08-16 08:45:21
【问题描述】:

我仍然卡在这里,我需要帮助我在不同设备上的 Android 应用。

 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.TextView;

 import androidx.annotation.NonNull;
 import androidx.recyclerview.widget.RecyclerView;

    public class Listadapter extends RecyclerView.Adapter<Listadapter.ListViewHolder>{

        String[] CourseTitle={"English - Lilly section", "English - Lilly section", "English - Lilly section",
                "English - Lilly section", "English - Lilly section", "English - Lilly section",
                "English - Lilly section",
                "English - Lilly section"};

        String[] Section={"Section (A)",
                "Section (A)","Section (A)", "Section (A)",
                "Section (A)","Section (A)","Section (A)","Section (A)"};

        String[] Coursedec={"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum",
                "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum",
                "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum",
                "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum",
                "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum",
                "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum",
                "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum",
                "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum"};

        @NonNull
        @Override
        public ListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.myrecylce_data,parent,false);
            return new ListViewHolder(view);


        }

        @Override
        public void onBindViewHolder(@NonNull ListViewHolder holder, int position) {
            holder.txt1.setText(CourseTitle[position]);
            holder.txt2.setText(Section[position]);
            holder.txt3.setText(Coursedec[position]);
        }

        @Override
        public int getItemCount() {
            return CourseTitle.length;
        }

        public class ListViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
            TextView txt1,txt2,txt3;
            public ListViewHolder(@NonNull View itemView) {
                super(itemView);
                txt1=itemView.findViewById(R.id.tv_onetxt);
                txt2=itemView.findViewById(R.id.tv_twotxt);
                txt3=itemView.findViewById(R.id.tv_dsc_course);
            }

            @Override
            public void onClick(View view) {

            }
        }
    }

什么都没发生,我不知道我是怎么做到的

【问题讨论】:

    标签: android android-studio android-fragments android-recyclerview


    【解决方案1】:

    我相信您希望在单击回收站视图项时执行一些操作。 为此,请参考您的 recyclerview_data 布局根元素。 这样做:

    public class Listadapter extends RecyclerView.Adapter<Listadapter.ListViewHolder>{
    
        String[] CourseTitle={"English - Lilly section", "English - Lilly section", "English - Lilly section",
                "English - Lilly section", "English - Lilly section", "English - Lilly section",
                "English - Lilly section",
                "English - Lilly section"};
    
        String[] Section={"Section (A)",
                "Section (A)","Section (A)", "Section (A)",
                "Section (A)","Section (A)","Section (A)","Section (A)"};
    
        String[] Coursedec={"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum",
                "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum",
                "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum",
                "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum",
                "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum",
                "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum",
                "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum",
                "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.The point of using Lorem Ipsum"};
    
        @NonNull
        @Override
        public ListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.myrecylce_data,parent,false);
            return new ListViewHolder(view);
    
    
        }
    
        @Override
        public void onBindViewHolder(@NonNull ListViewHolder holder, int position) {
            holder.txt1.setText(CourseTitle[position]);
            holder.txt2.setText(Section[position]);
            holder.txt3.setText(Coursedec[position]);
    
           holder.root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Perform your action here. In your case write code to pop your 
                  fragment
            }
        });
        }
    
        @Override
        public int getItemCount() {
            return CourseTitle.length;
        }
    
        public class ListViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
            TextView txt1,txt2,txt3;
            LinearLayout root; //Assuming your root tag is linear layout.
            public ListViewHolder(@NonNull View itemView) {
                super(itemView);
                txt1=itemView.findViewById(R.id.tv_onetxt);
                txt2=itemView.findViewById(R.id.tv_twotxt);
                txt3=itemView.findViewById(R.id.tv_dsc_course);
                 root=itemview.findViewById(R.id.root);
            }
    
        }
    }
    

    附带说明,最好使用接口回调从父活动中弹出片段。 希望对你有帮助

    【讨论】:

    • 感谢帮助而不是我使用的片段活动及其工作:D
    • 如果它解决了您的问题,请接受并支持答案
    猜你喜欢
    • 1970-01-01
    • 2018-05-17
    • 2021-12-30
    • 1970-01-01
    • 2021-04-12
    • 2022-09-26
    • 1970-01-01
    • 2018-04-24
    • 1970-01-01
    相关资源
    最近更新 更多