运行时错误:在使用recycleview

时间:2016-03-03 07:22:12

标签: android android-recyclerview

我试图在我的应用程序中放置一个列表,每个元素上都有一个监听器,点击它会打开一个带有该字段给出的参数的新活动。 听起来很简单但是当我从listview转到recyclerview时,我面临一个错误

我第一次点击某个项目时,只有第一个项目,需要5/6秒才能打开并抛出异常,如下所示

RuntimeException:执行停止未恢复的活动

关于保留列表的活动

这是我用于在视图中设置监听器的代码

公共静态类ViewHolder extends RecyclerView.ViewHolder实现了View.OnClickListener {

    private final AdapterRequestListController controller;
    // each data item is just a string in this case
    public TextView elapsedTime;
    public View rootView;

    public ViewHolder(View v, AdapterRequestListController controller) {
        super(v);
        elapsedTime = (TextView) v.findViewById(R.id.rlr_reply_title);
        rootView = v;
        this.controller = controller;
        v.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        controller.openReply(getAdapterPosition());
    }
}

我在控制器中寻找问题(实际上是我的活动)但没有任何改变,我转移到适配器,非常奇怪的是,如果我将监听器放在适配器的onbind方法中,它不会发生

我不喜欢把它放在那里有很多原因(每次滚动时都会更新大量的监听器)

有任何建议或想法吗?谢谢!

这是完整的例外

E/ActivityThread: Performing stop of activity that is not resumed: {it.mb.s/it.mb.s.working.ActivityVI}

java.lang.RuntimeException: Performing stop of activity that is not resumed: {it.mb.s/it.mb.s.working.ActivityVI}
                                                                            at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3465)
                                                                            at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3550)
                                                                            at android.app.ActivityThread.-wrap20(ActivityThread.java)
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                            at android.os.Looper.loop(Looper.java:148)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

更新2

这是实际运行意图的方法

@Override
public void openReply(int position) {
    //TODO
    Log.d(TAG, position + " fired");

    Intent intent = new Intent(this, ActivityViewReply.class);
    Bundle bundle = new Bundle();
    bundle.putSerializable(ActivityViewReply.REQUEST_FIELD_NAME, meRequests.get(position));
    intent.putExtras(bundle);
    startActivity(intent);

}

1 个答案:

答案 0 :(得分:0)

试试你的意图标志.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);