2017-12-14 14 views
1

このリストにImageViewを追加できますか?外部のURLListViewに画像のURLを追加するには?

item.putはちょうどURLリンクが追加されますが、それはそれは重複していないすべての

で画像を表示されません。このリストに画像をロードするために追加する必要があるコードを知りたいだけです。

try { 
    JSONObject object = new JSONObject(string); 
    JSONArray offers = object.optJSONArray("data"); 
    ArrayList<HashMap<String, String>> list = new ArrayList<>(); 

    HashMap<String, String> item; 
    for(int i = 0; i < offers.length(); i++) { 
     JSONObject jsonChildNode = offers.getJSONObject(i); 
     item = new HashMap<>(); 
     item.put("L1", jsonChildNode.optString("gate")); 
     item.put("L2", jsonChildNode.optString("stack")); 
     item.put("L3", jsonChildNode.optString("image")); 
     list.add(item); 
    } 

    sa = new SimpleAdapter(getActivity(), list, 
      R.layout.installs_item, 
      new String[]{"L1", "L2", "L3"}, 
      new int[]{R.id.gate, R.id.stack, R.id.image}); 
    installs.setAdapter(sa); 

} catch (JSONException e) { 
    e.printStackTrace(); 
} 

installs_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <TextView 
     android:id="@+id/L1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Head" 
     android:textSize="22sp" 
     android:textStyle="italic" /> 

    <TextView 
     android:id="@+id/L2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="sub" 
     android:textSize="14sp" /> 
    <TextView 
     android:id="@+id/L3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="desc" 
     android:textSize="14sp" /> 
    <ImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="" /> 
</LinearLayout> 
+0

あなたのレイアウトはどのように見えますか?> R.layout.installs_item、共有できますか? – RaniDevpr

+0

[リストビューのカスタムアダプタ](https://stackoverflow.com/questions/8166497/custom-adapter-for-list-view) – ADM

+0

の可能な複製を使用するhttps://github.com/bumptech/glide glide lib to URLを使用してイメージをロード –

答えて

0

はそのXMLでImageViewのが含まれている独自のアダプタを作成し、その中に画像を表示するためにグライドライブラリ(https://github.com/bumptech/glide)を使用

0

それは外部のlibを使用しますお勧めします負荷や画像処理プロセスを大幅に簡単にすることができます。

推奨LIB:http://square.github.io/picasso

これは、すでに使用されている画像を再利用し、データ使用量を削減します。

+0

このループに追加するには? 'item.put(" L3 "、jsonChildNode.optString(" image ")); String imageUrl = jsonChildNode.optString( "picture"); Picasso.with(getActivity())。load(imageUrl).into(imageView); list.add(item); ' – Fresco

+0

URLをリストアイテム(String)として追加し、URLを取得してアレイアダプタで同じコードを使用するだけです。 – Racer

+0

コードを書くことができるかどうかは分かりやすいでしょう。私はこのJavaベースのアンドロイドデベロッパにとっては全く新しいです – Fresco

関連する問題