如何在Android中使用Volley获取数组的第一个值?这个方法对我来说成功地从数组中获取了所有值,但是我只想只获取第一个值。
private void getValue(PriceModel priceModel, final ViewHolderPrice holder) {
StringRequest request = new StringRequest(
Request.Method.GET,
ServerApi.URL + priceModel.get_id(),
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if(!response.isEmpty()) {
Gson gson = new Gson();
PriceModel[] priceModels = gson.fromJson(response, PriceModel[].class); for(PriceModel price: priceModels) holder.tvPrice.setText(variantModels.getPrice());
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, error.getLocalizedMessage());
}
}
);
Volley.newRequestQueue(mContext).add(request);
}