我从json检索数据并在回收列表视图中设置onbind 如何在spinner product.setQuantity(quantity)中增加价值;每行
private ArrayList<ProductBySubCategory> parseJSONResponse(JSONArray response) {
ArrayList<ProductBySubCategory> listProducts = new ArrayList<ProductBySubCategory>();
if (response != null && response.length() > 0) {
try {
StringBuilder data = new StringBuilder();
JSONArray jsonArray = response;
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String pName = jsonObject.getString(KEY_NAME);
String pPrice = jsonObject.getString(KEY_PRICE);
String pUrlThumbnail = AppConfig.URL_THUBMNAIL_BASE + jsonObject.getString(KEY_THUMBNAIL);
String pSNo = jsonObject.getString(KEY_SNO);
String sellerName = jsonObject.getString(KEY_SELLER_NAME);
String qrValue = jsonObject.getString(KEY_QRVALUE);
String quantity = jsonObject.getString(KEY_QUANTITY);
data.append(pName + " " + pPrice + " " + pUrlThumbnail + " " + pSNo + " " + sellerName +" "+qrValue+ " "+quantity+ "\n");
ProductBySubCategory product = new ProductBySubCategory();
product.setpName(pName);
product.setSellerName(sellerName);
product.setQrValue(qrValue);
product.setpPrice(getString(R.string.material_icon_rupees)+pPrice);
product.setpUrlThumbnail(pUrlThumbnail);
product.setpSNo(pSNo);
product.setQuantity(quantity);
listProducts.add(product);
}
Log.d("Lifecycle2", listProducts.toString());
} catch (JSONException e) {
Log.d("Lifecycle", "Inside JSON EXCEPTION: " + e);
}
}
return listProducts;
}
在上面的代码中,我想为每一行调整微调器数量。
我在下面的代码中设置了适配器的值,但是我没有在文本视图中设置数量,因为我想在spinner中设置这个值,并且我为列表中的每个产品设置了微调器的数组值,现在应该怎么做如果可能的话,为每个项目的旋转器设置值,请给我一些代码。
@Override
public void onBindViewHolder(final ViewHolderProducts holder, int position) {
ProductBySubCategory currentProduct = productArrayList.get(position);
holder.productName.setText(currentProduct.getpName());
holder.sellerName.setText(currentProduct.getSellerName());
holder.qrValue.setText(currentProduct.getQrValue());
holder.productPrice.setText(currentProduct.getpPrice());
holder.btnBuy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
RelativeLayout relativeLayout = (RelativeLayout) view.getParent();
TextView textView = (TextView) relativeLayout.findViewById(R.id.qrValue);
String qrText = (String) textView.getText();
Log.d("Abhinav", "qrValue" +qrText);
if (buyItemClickListener != null) {
buyItemClickListener.buttonClicked(qrText);
}
}
});
String urlThumbnail = currentProduct.getpUrlThumbnail();
if (urlThumbnail != null) {
imageLoader.get(urlThumbnail, new ImageLoader.ImageListener() {
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean b) {
holder.productThumbnail.setImageBitmap(response.getBitmap());
}
@Override
public void onErrorResponse(VolleyError volleyError) {
}
});
}
}