0

I am using volley to get some JSON data.

How do I use the image src to populate my ImageView? Below response is the json data from dribbble. http://api.dribbble.com/shots/everyone?

The data will give me an image source

"image_url":"https://d13yacurqjgara.cloudfront.net/users/24831/screenshots/2112992/2015-06-18_19.51.18_copy.jpg"

How can I use that image source inside my ImageView

// BUILD THE ARRAY
JSONArray shots = response.getJSONArray("shots");
List<String> titles = new ArrayList<String>();
for (int i=0; i < shots.length(); i++) {
    JSONObject post = shots.getJSONObject(i);
    String title = post.getString("title");
    titles.add(title);
}

// You can see I am just taking that data and turning it into strings..
String[] titleArr = new String[titles.size()];
titleArr = titles.toArray(titleArr);

// SET THE ADAPTER
ListAdapter dribbbleFeedAdapter = new ArrayAdapter<String>(MainActivity.this,
        R.layout.feed_card,R.id.info_text,titleArr);
// SET THE LISTVIEW
ListView dribbbleDataListView = (ListView) findViewById(R.id.dribbbleFeedListView);
// SET THE LISTVIEW ADAPTER
dribbbleDataListView.setAdapter(dribbbleFeedAdapter);
// CHECK THE DATA
Log.d("this is my array", "arr: " + Arrays.toString(titleArr));

feed_card.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/card_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <!-- A CardView that contains a TextView -->
    <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        card_view:cardCornerRadius="2dp">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_weight="1"
                android:id="@+id/info_text"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:background="#aaa"
                android:id="@+id/dribbble_img"/>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <Button
                    android:layout_weight="1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Like" />
                <Button
                    android:layout_weight="1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Share" />
            </LinearLayout>

        </LinearLayout>



    </android.support.v7.widget.CardView>


</LinearLayout>
Squonk
  • 48,735
  • 19
  • 103
  • 135
Michael Joseph Aubry
  • 12,282
  • 16
  • 70
  • 135
  • Like this? http://stackoverflow.com/questions/2471935/how-to-load-an-imageview-by-url-in-android – isma3l Jun 19 '15 at 00:53
  • I don't really understand the question. If you have a URL to an image file you'll need to download that file, create a bitmap locally and use that for your `ImageView`. The `ImageView` class can't directly use a remote URL as its source. – Squonk Jun 19 '15 at 00:55
  • What is the best way to use an image from a url in android? It does not have to be an ImageView. – Michael Joseph Aubry Jun 19 '15 at 02:43

0 Answers0