Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7701143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:54:51+00:00 2026-05-31T22:54:51+00:00

In for loop it displaying only last data. In database how many rows are

  • 0

In for loop it displaying only last data. In database how many rows are there so many rows are getting displayed by taking the last item
all the rows are taking last image and text
Now i want display all the images and text from the database in listview.please help me

enter code here
  public class ImageAdapter extends BaseAdapter {
private static final Context Context = null;
String qrimage;
Bitmap bmp, resizedbitmap;
Activity activity = null;
private static LayoutInflater inflater;

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

public ImageAdapter(Context context, JSONArray imageArrayJson) {
    //inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  //  imageLoader=new ImageLoader(activity);
    inflater=LayoutInflater.from(context);
    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"));


            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);
        }
        System.out.println(map);

    } 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 vi=convertView;

            vi = inflater.inflate(R.layout.listview, null);


       TextView text=(TextView)vi.findViewById(R.id.text);
        ImageView image=(ImageView)vi.findViewById(R.id.image);
        image.setImageBitmap(bmp);
        text.setText(map.get("itemname"));

        return vi;


 }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:54:53+00:00Added an answer on May 31, 2026 at 10:54 pm

    this line is going to store everything in one spot in the map:

    map.put("itemname", image.getString("itemname"));
    

    but perhaps you meant:

    map.put(itemname, image.getString("itemname"));
    

    also you have one field for bmp that gets reset each time through the loop. your getView method has a position parameter for a reason, so it can index into an array and find the appropriate information for that spot in the list. instead your getView is retrieving the one bmp and the one itemname for the whole adapter instance — not indexed by position as it ought to be.

    I probably shouldn’t be just giving you the code, but here it is.

    public class ImageAdapter extends BaseAdapter {
      String qrimage;
      Bitmap bmp, resizedbitmap;
      Bitmap[] bmps;
      Activity activity = null;
      private LayoutInflater inflater;
    
      private ImageView[] mImages;
      String[] itemimage;
      TextView[] tv;
      String itemname;
      String[] itemnames;
      HashMap<String, String> map = new HashMap<String, String>();
    
      public ImageAdapter(Context context, JSONArray imageArrayJson) {
        //inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //  imageLoader=new ImageLoader(activity);
        inflater=LayoutInflater.from(context);
        this.mImages = new ImageView[imageArrayJson.length()];
        this.bmps = new Bitmap[imageArrayJson.length()];
        this.itemnames = new String[imageArrayJson.length()];
    
        try {
    
          for (int i = 0; i < imageArrayJson.length(); i++) {
            JSONObject image = imageArrayJson.getJSONObject(i);
            qrimage = image.getString("itemimage");
            itemname = image.getString("itemname");
            itemnames[i] = 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);
            bmps[i] = bmp;
    
            mImages[i] = new ImageView(context);
            mImages[i].setImageBitmap(resizedbitmap);
    
            mImages[i].setScaleType(ImageView.ScaleType.FIT_START);
    
    
            // tv[i].setText(itemname);
          }
          System.out.println(map);
    
        } 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 vi=convertView;
    
        vi = inflater.inflate(R.layout.listview, null);
    
    
        TextView text=(TextView)vi.findViewById(R.id.text);
        ImageView image=(ImageView)vi.findViewById(R.id.image);
        image.setImageBitmap(bmps[position]);
        text.setText(itemnames[position]);
    
        return vi;
    
    
      }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a weird problem my while loop is not incrementing like its displaying
i have php while loop, creates many classes, displaying info (user posts ect) and
I have a loop displaying records, and I want to add submit buttons to
This loop checks if a record is in the sqlite database and builds a
I am trying to loop though my users database to show each username in
I'm having a lot of problems getting mutual friends between users and displaying those
I have divs created within a while loop displaying a MySQL query. I'd like
Hello Stack i have the below code and it only seems to loop once,
I have an ul list with a query and a while loop displaying the
I have a while loop that is going through and displaying an RSS icon

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.