0

i am get the images from mysql database to my android mobile . i want to display image along with names enter code here Main.java

 JSONArray json = jArray.getJSONArray("names");
        list=(ListView)findViewById(R.id.list);
         adapter=new ImageAdapter(this, json);
         list.setAdapter(adapter);

 Image adapter.java

 public class ImageAdapter extends BaseAdapter {
Bitmap bmp;
private static LayoutInflater inflater = null;

private ImageView[] mImages;
String[] itemimage;

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

public ImageAdapter(Context context, JSONArray imageArrayJson) {
    this.mImages = new ImageView[imageArrayJson.length()];
    String qrimage;
    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;
      Bitmap resizedbitmap =                                          
             Bitmap.createScaledBitmap(bmp,width,
                    height, true);

            Log.e("Image Height", " Height = " + bmp.getHeight()
                    + " , Width = " + bmp.getWidth());

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

            mImages[i].setScaleType(ImageView.ScaleType.FIT_START);

        }

    } 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) {


    return mImages[position];

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

<ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     />


 </LinearLayout>

the above code i can able to view the images from the mysql database from server to my android mobile. i want display itemimages along with item names in list view in base adapter get view i can display all images.like that i want display all item names. i print itemnames it print all names from database . i want display images and names in list view

Sulochna S
  • 1
  • 1
  • 2

3 Answers3

0

you need a custom row in your list view. so create a file called row.xml under layout and then using a simple cursor adapter you can give the list view two values, the image and the text

kennie
  • 11
  • 4
0

instead of using base adapter try array adapter and get help from here

http://www.vogella.de/articles/AndroidListView/article.html#adapterperformance_standard

vipin
  • 2,851
  • 4
  • 18
  • 32
  • http://stackoverflow.com/questions/459729/how-to-display-list-of-images-in-listview-in-android – vipin Mar 26 '12 at 11:22
0

you can create a list activity for display elements and also create a separate xml layout file which will have the design of your single element of the list. its called creating a custom list view. have a look at this tutorial http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/ for further information.

Anurag Ramdasan
  • 4,189
  • 4
  • 31
  • 53
  • 1
    for your problem, all you need would be an imageview and a textview in xml. i guess you will be able to manage beyond that. – Anurag Ramdasan Mar 26 '12 at 14:20
  • i would suggest you take a look at the code provided [here](http://stackoverflow.com/questions/6305899/custom-listview-android) . i suppose this is exactly what you want. – Anurag Ramdasan Mar 26 '12 at 14:29
  • this example images are not getting from database . they taken from drawable. i want customized layout using base adapter – Sulochna S Mar 26 '12 at 14:33