我正在使用volley
来获取一些JSON数据。
如何使用图像src填充我的ImageView?低于response
的是来自dribbble的json数据。 http://api.dribbble.com/shots/everyone?
数据将为我提供图像源
"image_url":"https://d13yacurqjgara.cloudfront.net/users/24831/screenshots/2112992/2015-06-18_19.51.18_copy.jpg"
如何在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>