回收器查看项目点击并不总是有效,有时可以工作,但点击更多(不知道点击多少次)



Recyclerview项单击并不总是有效,有时可以使用更多,而是使用更多单击(不知道有多少单击)。如果只需单击一次无法单击即可。

NOTE 几天前我尝试单击一次,但现在尝试再次运行,因为它不起作用,即使我没有修改该文件

我的代码

public class RecyclerViewAdapterRiwayat extends RecyclerView.Adapter<RecyclerViewAdapterRiwayat.ViewHolder> {
    Context context;
    private static final String TAG = RecyclerViewAdapterRiwayat.class.getSimpleName();
    List<GetDataAdapterRiwayat> getDataAdapter;
    ImageLoader imageLoader1;
    String FIXURL = "http://192.168.1.101/AndroidFileUpload/";
    String url = FIXURL + "uploads/";
    String StatusRiwayat;

    public RecyclerViewAdapterRiwayat(List<GetDataAdapterRiwayat> getDataAdapter, Context context) {
        super();
        this.getDataAdapter = getDataAdapter;
        this.context = context;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_items_riwayat, parent, false);
        ViewHolder viewHolder = new ViewHolder(v);
        return viewHolder;
    }
    @Override
    public void onBindViewHolder(ViewHolder Viewholder, int position) {
        final GetDataAdapterRiwayat getDataAdapter1 = getDataAdapter.get(position);
        imageLoader1 = ServerImageParseAdapter.getInstance(context).getImageLoader();
        imageLoader1.get(url+getDataAdapter1.getFotoSetelahRiwayat(),
                ImageLoader.getImageListener(
                        Viewholder.networkImageView,//Server Image
                        R.mipmap.ic_launcher,//Before loading server image the default showing image.
                        android.R.drawable.ic_dialog_alert //Error image if requested image dose not found on server.
                )
        );
        Viewholder.networkImageView.setImageUrl(url+getDataAdapter1.getFotoSetelahRiwayat(), imageLoader1);

        Viewholder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "coba nih5 : "+getDataAdapter1.getNamaJalanRiwayat());
                Intent intent = new Intent(v.getContext(), DetailRiwayatActivity.class);
                context.startActivity(intent);
            }
        });
    }
    @Override
    public int getItemCount() {
        return getDataAdapter.size();
    }
    class ViewHolder extends RecyclerView.ViewHolder{
        public TextView ImageTitleNameView;
        public NetworkImageView networkImageView;
        public ViewHolder(View itemView) {
            super(itemView);
            ImageTitleNameView = (TextView) itemView.findViewById(R.id.textView_item_riwayat);
            networkImageView = (NetworkImageView) itemView.findViewById(R.id.VollyNetworkImageView2);
        }

    }
}

如果您仅在滚动/拿起回收库后遇到问题,则它是supportLibrary

中的已知错误

用户滚动后,他们无法单击Recyclerview中的项目。(AOSP问题66996774)

issuetracker ID 66996774以及69823266,因为它仍未在27.0.1中固定。即使Google指出它已修复。

最重要的是:修复此处(由Chris Banes,Googler)运作完美:https://gist.github.com/chrisbanes/8391b5adb9ee421808933008508502f2

尝试以下:

   class ViewHolder extends RecyclerView.ViewHolder{
            public TextView ImageTitleNameView;
            public NetworkImageView networkImageView;
            public ViewHolder(View itemView) {
                super(itemView);
                ImageTitleNameView = (TextView) itemView.findViewById(R.id.textView_item_riwayat);
                networkImageView = (NetworkImageView) itemView.findViewById(R.id.VollyNetworkImageView2);

                itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                int position = getLayoutPosition(); // use this to get item from list
                    Log.d(TAG, "coba nih5 : "+getDataAdapter1.getNamaJalanRiwayat());
                    Intent intent = new Intent(v.getContext(), DetailRiwayatActivity.class);
                    context.startActivity(intent);
                }
            });
        }

您的代码

Viewholder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "coba nih5 : "+getDataAdapter1.getNamaJalanRiwayat());
                Intent intent = new Intent(v.getContext(), DetailRiwayatActivity.class);
                context.startActivity(intent);
            }
        });

每次创建新的侦听器到ItemView,而是在分配新侦听器

之前实现OnClickListener或Pass null
 Viewholder.itemView.setOnClickListener(null);
Viewholder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "coba nih5 : "+getDataAdapter1.getNamaJalanRiwayat());
                Intent intent = new Intent(v.getContext(), DetailRiwayatActivity.class);
                context.startActivity(intent);
            }
        });

或在ViewHolder onCreateViewHolder()

中添加侦听器
v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                int position = viewHolder.getAdapterPosition(); // use this to get item from list
                    Log.d(TAG, "coba nih5 : "+getDataAdapter1.getNamaJalanRiwayat());
                    Intent intent = new Intent(v.getContext(), DetailRiwayatActivity.class);
                    context.startActivity(intent);
                }
            });

将它们添加到您的父元素r.layout.recyclerview_items_riwayat

android:clickable="false"
android:focusable="false"

将其添加到项目布局的儿童视图(不是root element只有childs !!)(r.layout.recyut.recyclerview_items_riwayat):

android:clickable="false"
android:focusable="false"

这可能是由于父母的onTouch方法拦截了触摸事件。您需要检查是否有 SwipeLayout等父视图。

相关内容

  • 没有找到相关文章

最新更新