Wie Konvertieren von Bild-url in Drawable Int

Guten Morgen Alle !!!!

Ich versuche, um die Bilder in der Bildansicht. Aber Meine Forderung ist ,die ich brauche, um die Bilder in den Drawable-Integer-Format.Ich bin immer Daten vom Server und das erste Bild im url-format..

For ex :http://www.mymartmycart.com/images/detailed/3/4G_CONNECT_M1.jpeg

Ich will zu konvertieren, das Bild in Drawable-Format.

Das ist Mein code

Dies ist mein Interface

 public interface ECCardData<T> {

    @DrawableRes
    Integer getMainBackgroundResource();

    @DrawableRes
    Integer getHeadBackgroundResource();

    List<T> getListItems();
}

Meine Getter-und Setter -

     private Integer headBackgroundResource;

public Integer getHeadBackgroundResource() {
        return headBackgroundResource;
    }

    public void setHeadBackgroundResource(Integer headBackgroundResource) {
        this.headBackgroundResource = headBackgroundResource;
    }

Diesen code, wo ich Bilder

Integer drawableRes = dataset.get(position).getHeadBackgroundResource();
    if (drawableRes != null) {
        headView.setHeadImageBitmap(BitmapFactory.decodeResource(pagerContainer.getResources(), drawableRes, new BitmapFactoryOptions()));
    }

Dies ist meine Analyse

 public static ArrayList<CardData> ParseCraft(String response) throws JSONException {


        ArrayList<CardData> alUser = new ArrayList<>();

        JSONObject jsonRoot = new JSONObject(response);

        JSONArray parentArray = jsonRoot.getJSONArray("products");

        for (int j = 0; j < parentArray.length(); j++) {

            JSONObject finalObject = parentArray.getJSONObject(j);

            CardData user = new CardData();

            user.setHeadTitle(finalObject.getString("product"));
            user.setPersonName(finalObject.getString("product_code"));

            JSONObject productJsonObject = finalObject.getJSONObject("main_pair");
            JSONObject productJsonObject1 = productJsonObject.getJSONObject("detailed");

            user.setHeadBackgroundResource(productJsonObject1.getString("image_path"));



            alUser.add(user);
        }

        return alUser;
    }

Meine json-Antwort

{
"products": [
    {
        "product_id": "863",
        "product": "LAVA 4G CONNECT M1",
        "company_name": "SAPTHAGIRI MOBILES",
        "age_verification": "N",
        "age_limit": "0",
        "product_code": "SGMM00044",
        "product_type": "P",
        "status": "A",
        "company_id": "34",
        "approved": "Y",
        "list_price": "0.00",
        "amount": "2",
        "weight": "0.000",
        "length": "0",
        "width": "0",
        "height": "0",
        "shipping_freight": "0.00",
        "low_avail_limit": "0",
        "timestamp": "1492758588",
        "updated_timestamp": "1500273558",
        "usergroup_ids": "0",
        "is_edp": "N",
        "edp_shipping": "N",
        "unlimited_download": "N",
        "tracking": "B",
        "free_shipping": "N",
        "zero_price_action": "R",
        "is_pbp": "N",
        "is_op": "N",
        "is_oper": "N",
        "is_returnable": "Y",
        "return_period": "10",
        "avail_since": "0",
        "out_of_stock_actions": "N",
        "localization": "",
        "min_qty": "0",
        "max_qty": "0",
        "qty_step": "0",
        "list_qty_count": "0",
        "tax_ids": "",
        "options_type": "P",
        "exceptions_type": "F",
        "details_layout": "default",
        "shipping_params": "a:5:{s:16:\"min_items_in_box\";i:0;s:16:\"max_items_in_box\";i:0;s:10:\"box_length\";i:0;s:9:\"box_width\";i:0;s:10:\"box_height\";i:0;}",
        "facebook_obj_type": "activity",
        "buy_now_url": "",
        "cod": "N",
        "price": "3094.000000",
        "category_ids": [
            295
        ],
        "position": "0",
        "seo_name": "lava-4g-connect-m1",
        "seo_path": "166/234/295",
        "average_rating": null,
        "discussion_type": "D",
        "discussion_thread_id": "619",
        "main_category": 295,
        "main_pair": {
            "pair_id": "2577",
            "image_id": "0",
            "detailed_id": "3266",
            "position": "0",
            "detailed": {
                "object_id": "863",
                "object_type": "product",
                "image_path": "http://www.mymartmycart.com/images/detailed/3/4G_CONNECT_M1.jpeg",
                "alt": "",
                "image_x": "635",
                "image_y": "476",
                "http_image_path": "http://www.mymartmycart.com/images/detailed/3/4G_CONNECT_M1.jpeg",
                "https_image_path": "https://www.mymartmycart.com/images/detailed/3/4G_CONNECT_M1.jpeg",
                "absolute_path": "/home/mymartmycart/public_html/images/detailed/3/4G_CONNECT_M1.jpeg",
                "relative_path": "detailed/3/4G_CONNECT_M1.jpeg"
            }
        },
        "base_price": "3094.000000",
        "selected_options": [],
        "has_options": false,
        "product_options": [],
        "discounts": {
            "A": 0,
            "P": 0
        },
        "product_features": [],
        "qty_content": []
    }
  • dies könnte etwas Hilfe : stackoverflow.com/questions/3375166/...
  • wenn Sie nur zeigen wollten das Bild kommt vom server-url in Ihrem Bildansicht Sie können gleiten oder picaso-Bibliothek, um die Anzeige direkt zu Bildansicht
  • Sie können auch konvertieren Sie Ihre url in die bitmap und setzen Sie die bitmap zu Ihrer Bildansicht hier ist ein link zu konvertieren url-bitmap stackoverflow.com/questions/11831188/...
  • ok. lassen Sie mich versuchen, diese
  • Aber wenn statische Bilder, die ich anzeigen mit obigen code?@ Snehal Gongle Jetzt, ich habe eine Anzeige-server-images .Bitte Überprüfen Sie mein interface code oben
  • R.drawable.something ist eine resource-ID erstellt, die während der Kompilierung und nicht Sie "hinzufügen" / "konvertieren" das heruntergeladene Bild in R.drawable Ihre interface-design falsch ist - sollten Sie android.graphics.drawable.Drawable - Konzept statt
  • schauen Sie entfernen müssen Ihrem diesem code und Stelle glide code Benutzer.setHeadBackgroundResource(productJsonObject1.getString("abbildpfad")); Glide.mit(Kontext -) .load(url) .in(Bildansicht);
  • warum wollen Sie dies, wenn Sie möchten, um das Bild, die Sie verwenden können picasso

Schreibe einen Kommentar