0

I can able to fetch the images from mysql db to android using json to the list view . i want display Image and text as listview

enter code here
 Main.java
  JSONArray json = jArray.getJSONArray("names");
        list=(ListView)findViewById(R.id.list);
         adapter=new ImageAdapter(this, json);
         list.setAdapter(adapter);
  ImageAdapter.java
    public class ImageAdapter extends BaseAdapter {
String qrimage;
Bitmap bmp, resizedbitmap;
private static LayoutInflater inflater = null;

private ImageView[] mImages;
String[] itemimage;
TextView[] tv;
String itemname;
HashMap<String, String> map = new HashMap<String, String>();

public ImageAdapter(Context context, JSONArray imageArrayJson) {
    this.mImages = new ImageView[imageArrayJson.length()];

    try {

        for (int i = 0; i < imageArrayJson.length(); i++) {
            JSONObject image = imageArrayJson.getJSONObject(i);
            qrimage = image.getString("itemimage");
            itemname = image.getString("itemname");
            map.put("itemname", image.getString("itemname"));
            System.out.println(itemname);

            byte[] qrimageBytes = Base64.decode(qrimage.getBytes());

            bmp = BitmapFactory.decodeByteArray(qrimageBytes, 0,
                    qrimageBytes.length);
            int width = 100;
            int height = 100;
            resizedbitmap = Bitmap.createScaledBitmap(bmp, width, height,
                    true);

            mImages[i] = new ImageView(context);
            mImages[i].setImageBitmap(resizedbitmap);

            mImages[i].setScaleType(ImageView.ScaleType.FIT_START);
            // tv[i].setText(itemname);
        }

    } catch (Exception e) {
        // TODO: handle exception
    }
}

public int getCount() {
    return mImages.length;
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    /* View row=inflater(R.layout.listview,null);
        TextView text=(TextView)row.findViewById(R.id.text);
                ImageView image=(ImageView)row.findViewById(R.id.image);

      text.setText(itemname[position]);
               image.setImageBitmap(resizedbitmap[pos]);
        return row;*/
    return mImages[position];
}

   }

The above code i can print itemname. means it print all item names in logcat. i can only view images only in listview. how can append text view into itemname how to display itemimage and itemname as listview.. please don't give other examples please tell me what can i do other wise modify code where i can mistake.. please help me

4
  • 1
    exact duplicate of stackoverflow.com/questions/9884565/… Commented Mar 27, 2012 at 9:54
  • i tried but i cannot get original answer thats why i can post again Commented Mar 27, 2012 at 10:13
  • How your getting image from web... Commented Mar 27, 2012 at 10:20
  • yes i am getting from image using web Commented Mar 27, 2012 at 10:33

1 Answer 1

1

You can use this code to display the image. ClueImgURL is the url of the image.

       InputStream is = null;
            try {
                is = (InputStream) new URL(ClueImgURL).getContent();
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace(); 
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        Drawable d = Drawable.createFromStream(is, "src name");
        mImages[i].setBackgroundDrawable(d);
Sign up to request clarification or add additional context in comments.

1 Comment

this i cannot implement . please in get view method i want create new layout. and add mimages and itemname please give like that code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.