我试图将我的 json 数据放入 listview 属性,但数据未显示在属性中。数据显示在运行窗口中。如何将数据放入属性中?我使用 fragment 来显示 listview enter image description here
我的主要片段:
api = retrofitClient.getClient("http://10.8.0.2:5000/").create(Api.class);
String encoding = Base64Encoder.encode(UtilsApi.username + ":" + UtilsApi.password);
Log.d(TAG, "listsensor: "+api.listSensor(UtilsApi.username,UtilsApi.password,"Basic "+encoding));
api.listSensor(UtilsApi.username, UtilsApi.password, "Basic " + encoding)
.enqueue(new Callback<List<Sensor>>() {
@Override
public void onResponse(Call<List<Sensor>> call, Response<List<Sensor>> response) {
if (response.isSuccessful()) {
try {
Toast.makeText(getActivity().getApplicationContext(),"Success",Toast.LENGTH_SHORT).show();
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
OkHttpClient client = new OkHttpClient();
JSONObject jsonRESULTS = new JSONObject(response.body().toString());
sensors = (List<Sensor>) response.body();
listView.setAdapter(new SensorListAdapter(getActivity().getApplicationContext(), sensors));
}catch (JSONException e){
e.printStackTrace();
}
}else {
Toast.makeText(getActivity().getApplicationContext(), "Sensor Failed", Toast.LENGTH_LONG).show();
}
}
}
});
}
天涯尽头无女友
相关分类