I have button in recycler view when I click it I want to change the text of button and make network call with volly.
I am getting this Exception
Java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
So, I checked this answer and created a class extending Thread class and made the network call in it, and called it from adapter
But it is still showing the same error.
I am not understanding what I need to execute on main thread and what on new thread.
This is the call from the recycler-view adapter
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();
}
}
});
and I am calling Volley-POST method in MyThread class in run() method.
How can I fix this?