0

当我单击它时,我在回收站视图中有按钮我想更改按钮的文本并使用 volly 进行网络调用。

我收到了这个异常

Java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

所以,我检查了这个答案 并创建了一个扩展 Thread 类的类并在其中进行网络调用,并从适配器调用它

但它仍然显示相同的错误。

我不明白我需要在主线程上执行什么以及在新线程上执行什么。

这是来自 recycler-view 适配器的调用


pdc_viewHolder.toggleButton_paymentStatus.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean toggleOn) {
                if (toggleOn) {
                    // Toggle on = PAID
                    // Change the color of background

 pdc_viewHolder.activity_dashboard_recyclerView_row_toggleButton_paymentStatus.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.shape_layout_toggle_button_dashboard_paid_state));

                   MyThread myThread = new MyThread(bankNameAdap, context);
                    myThread.start();

                } else if (!toggleOn) {
                    // Toggle off = PENDING
                     //Change the toggle button background 
 pdc_viewHolder.activity_dashboard_recyclerView_row_toggleButton_paymentStatus.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.shape_layout_toggle_button_dashboard_pending_state));


                     MyThread myThread = new MyThread(bankNameAdap, context);
                    myThread.start();

                }
            }
        });

我在 run() 方法的 MyThread 类中调用 Volley-POST 方法。

我怎样才能解决这个问题?

4

0 回答 0