2016-03-03 64 views
0

我试图在每个元素上添加一个侦听器,在其中点击它的每个元素的列表中打开一个新的活动,并使用该字段给定的参数。 这听起来很容易,但是当我从listview移动到recyclerview时,我正面临着一个错误运行时错误:在继续之前停止回收视图

我第一次点击一个项目,只有第一个,它需要5/6秒才能打开并引发异常以下

的RuntimeException:执行未对保持列表中的活性恢复

活动的停止

这是我使用的设置听者在viewholder代码

公共静态类ViewHolder扩展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()); 
    } 
} 

我看着在控制器的问题(实际上是我的活动),但什么都没有改变,AO我搬到了适配器和非常奇怪的是,如果我把听者在适配器的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); 

} 
+0

请显示您的整个堆栈跟踪。 – barq

+0

我更新了整个堆栈的问题 –

+0

您是否在该点击事件上开始了相同的活动? –

回答

0

尝试标志你的意图的方法。 setFlags(Intent.FLAG_ACTIV ITY_NEW_TASK);

+0

正如我所说的那样,但我不想把它在那里,它不是最优:http://stackoverflow.com/questions/24885223/why-doesnt-recyclerview-have-onitemclicklistener-and-how-recyclerview-is-dif 因为他们写在答案是非常糟糕的将监听器放在绑定方法中,因为滚动时会创建大量的监听器 –

+0

** controller.openReply **方法的用途是什么? –

+0

它开始一个活动,意图将一个参数广告额外绑定 Intent intent = new Intent(this,DisplayMessageActivity.class); String message = mylist.get(position).toString(); 意图。putExtra(EXTRA_MESSAGE,message); startActivity(intent); –