0

this is my code and it's working good. i want to get multiple values (including image address) from my JSON data and show them in each row of my listview but i couldn't do that i just could get one data (title) and put that in simple list, how i can replace android.R.layout.simple_list_item_1 with my own single row layout? i'm new to android and i couldn't understand wheres the loop of listviews and rows.

what i wanna do is get some datas from JSON and show them in my custom row layout, something like google plus list view, with images, title and description

sorry for my bad english:)

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;
    setContentView(R.layout.activity_read_restaurants);
    restaurantList = (ListView) findViewById(R.id.restaurantList);


    final ArrayAdapter<String> restaurantAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,restaurantArray);
    restaurantList.setAdapter(restaurantAdapter);

    RequestQueue rq = Volley.newRequestQueue(this);
    JsonObjectRequest jsonrequest = new JsonObjectRequest(Request.Method.GET,feedURL,null,
            new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    try {
                        JSONArray restaurants = response.getJSONArray("posts");
                        for (int i =0; i<restaurants.length(); i++){
                            restaurantArray.add(restaurants.getJSONObject(i).getString("title"));
                        }
                    } catch (JSONException e) {

                        e.printStackTrace();
                    }
                    restaurantAdapter.notifyDataSetChanged();
                }

            },new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(context, error.toString(), Toast.LENGTH_LONG).show();

                }
            });


    rq.add(jsonrequest);
}
Siavash
  • 21
  • 1
  • 8
  • hi, android.R.layout.simple_list_item_1 is default by android system and can have only one textview in it.replace it with your own layout that can have more than one textview and inflate it – Maulik Sheth Oct 14 '13 at 17:41
  • thanks for your answer, i tried to do this multiple times, i made my own layout for row but i don't know where and how to get data and set text (and or image src) to my layout items – Siavash Oct 14 '13 at 17:48
  • Create a class extending ArrayAdapter and override the getView method to inflate your custom row – Mikel Oct 14 '13 at 17:53
  • possible duplicate of [How to use ArrayAdapter](http://stackoverflow.com/questions/2265661/how-to-use-arrayadaptermyclass) – Moog Oct 14 '13 at 17:53

1 Answers1

1

check this tutorial to create arrayadapter and use it in your program

http://theopentutorials.com/tutorials/android/listview/android-custom-listview-with-image-and-text-using-arrayadapter/

it even implements View Holder pattern.

Maulik Sheth
  • 584
  • 3
  • 10