为什么没有从适配器类传递意图? [英] Why intent is not passed from adapter class?

查看:73
本文介绍了为什么没有从适配器类传递意图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我正在尝试在单击item时从适配器类传递意图.尽管这听起来可能是一个正常的或愚蠢的问题,但是从最近3天4天开始我就被困在这个问题上.最初,我以为itemView没有收到点击,但是后来我尝试在onClick()方法中进行祝酒,但奇怪的是,它祝酒的消息没有任何问题或错误,但没有传递意图.我不知道为什么这种奇怪的行为发生了.我曾尝试在 SO 中搜索很多问题,但这些问题都没有帮助.

Actually I'm trying to pass intent from adapter class on click of item . Although it may sound a normal or foolish question but I'm stuck in it from last 3 4 days . At first I was thinking that the itemView is not receiving the click but then I tried to put a toast inside the onClick() method but the strange part is it's toasting the message without any problem or error but it's not passing intent . I don't know why this strange behavior is happening . I've tried to search a lot of questions in SO but none of them were helpful.

代码:

 //opening img on clik
        holder.itemView.setClickable(true);
        holder.itemView.setFocusable(true);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(ctx,"testing",Toast.LENGTH_SHORT).show();
                Bundle b = new Bundle();
                b.putString("what", "show_post");
                b.putString("timelineData", gson.toJson(totalList));
                b.putInt("position",holder.getAdapterPosition());
                Intent i = new Intent(ctx, ProfileHolder.class);
                i.putExtras(b);
                i.putExtra("Open", "starred");
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                ctx.startActivity(i);
            }
        });

推荐答案

  • 删除i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);您不需要
  • ProfileHolder是活动吗?似乎不是一个.
  • 如果ProfileHolder确实是一个Activity,请检查它是否已在AndroidManifest.xml文件中注册.
    • remove i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); you don't need that
    • is ProfileHolder an Activity? It doesn't seem to be one.
    • if ProfileHolder is really an Activity, check that it is registered in the AndroidManifest.xml file.
    • 这篇关于为什么没有从适配器类传递意图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆