@lzs1024
我没改okhttpcient以及后端代码。我也不知道,后来就好了。
为spinner绑定了onItemSelected,然后再调用线程。
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
switch (i) {
case 0:
Thread thread1 = new Thread(runnable1);
thread1.start();
break;
case 1:
Thread thread2 = new Thread(runnable2);
thread2.start();
break;
case 2:
// 暂时不支持
break;
case 3:
Thread thread4 = new Thread(runnable4);
thread4.start();
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
然后在线程中,调用了okhttpclient
Runnable runnable1 = new Runnable() {
@Override
public void run() {
productOkHttp http = new productOkHttp();
try {
List<product> products = http.getProduct();
handleData(products,http);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};