データベースから取得した画像 URL があり、画像ビュー内に表示したいと考えています。私はこの目的で Glide ライブラリを使用していますが、Exception
しばらくdoInBackground
実行しています。
public class Main extends Fragment implements OnClickListener {
private static String url = "http://timit.ir/select/select_pro";
private static final String TAG_SUCCESS = "success";
private static final String TAG_PRODUCTS = "product";
private static final String TAG_PID = "Pro_ID";
public static final String TAG_PIMAGE = "Url";
public static final String TAG_PNAME = "Pro_Name";
public static final String TAG_PRICE = "Price";
public static final String TAG_DESCRIPTION = "description";
public static final String TAG_OLDPRICE = "oldPrice";
public static final String TAG_COMPANYNAME = "companyName";
public List<Card> cardList;
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.frag_main, container, false);
l1 = (LinearLayout)rootView.findViewById(R.id.horizontal1);
l2 = (LinearLayout)rootView.findViewById(R.id.horizontal2);
new LoadAllProducts().execute();
return rootView;
}
class LoadAllProducts extends AsyncTask<String, String, List<Card>> {
@Override protected List<Card> doInBackground(String... args) {
cardList = new ArrayList<Card>();
JSONObject json = jParser.makeHttpRequest(url, "GET", params);
// Check your log cat for JSON reponse
Log.d("All Products: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
products = json.getJSONArray(TAG_PRODUCTS);
// looping through All Products
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
Card card = new Card(getActivity());
Log.d("url:", c.getString(TAG_PIMAGE));
Glide.with(Main.this).load(c.getString(TAG_PIMAGE)).into(card.productThumbnailImage);
card.productId = c.getString(TAG_PID);
card.productName.setText(c.getString(TAG_PNAME));
card.price.setText(c.getString(TAG_PRICE));
card.description.setText(c.getString(TAG_DESCRIPTION));
card.companyName.setText(c.getString(TAG_COMPANYNAME));
card.oldPrice.setText(c.getString(TAG_OLDPRICE));
cardList.add(card);
}
return cardList;
}
} catch (JSONException e) {
e.printStackTrace();
}
return cardList;
}
@Override protected void onPostExecute(List<Card> lcard) {
super.onPostExecute(lcard);
if (lcard.size() != 0) {
for (int i = 0; i < lcard.size(); i++) {
l1.addView(lcard.get(i));
}
}
}
}
}
私のログ:
07-02 11:38:59.506: D/url:(4967): http://timit.ir/product_pic /iphone6plusthumnail.png