vendredi 29 août 2014

Add images to a listview using Picasso after loading informations using JSON


Vote count:

0




i created a listview using JSON to load informations from a certain url here's my layout file



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/back_list" >

<ImageView
android:id="@+id/Img_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/helleb"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/vers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="you"
android:textSize="20sp"
android:textStyle="bold"
/>

<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="i"
android:textSize="15sp"
/>

<TextView
android:id="@+id/api"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="us"
android:textSize="10sp"
/>
</LinearLayout>


</LinearLayout>


i loaded the informations from JSON to the textviews present in the xml file now i want to load the corresponding images to the same list in the imageview "Img_type"


is this the right sentence?



Picasso.with(list.getContext()).load("http://ift.tt/1C8L0Ty"+Product_id).into(IM);


i'm getting errors and where do i have to put it? is this right?



protected void onPostExecute(JSONObject json) {
pDialog.dismiss();
try {
// Getting JSON Array from URL
android = json.getJSONArray(TAG_OS);
for(int i = 0; i < android.length(); i++){
JSONObject c = android.getJSONObject(i);

// Storing JSON item in a Variable
String ver = c.getString(TAG_VER);
String name = c.getString(TAG_NAME);
String api = c.getString(TAG_API);
String product_id=c.getString(Product_id);



// Adding value HashMap key => value


HashMap<String, String> map = new HashMap<String, String>();

map.put(TAG_VER, ver);
map.put(TAG_NAME, name);
map.put(TAG_API, api);

oslist.add(map);
list=(ListView)findViewById(R.id.list);





ListAdapter adapter = new SimpleAdapter(MainActivity.this, oslist,
R.layout.list_v,
new String[] { TAG_VER,TAG_NAME, TAG_API }, new int[] {
R.id.vers,R.id.name, R.id.api});

Picasso.with(list.getContext()).load("http://ift.tt/1C8L0Ty"+Product_id).into(IM);

list.setAdapter(adapter);


asked 16 secs ago







Add images to a listview using Picasso after loading informations using JSON

Aucun commentaire:

Enregistrer un commentaire