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

  • SEARCH
  • Home
  • 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 3800152
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:50:55+00:00 2026-05-19T13:50:55+00:00

I am trying to load a list of images from an array. I got

  • 0

I am trying to load a list of images from an array. I got the images in list. Now I need to add a text for every image in the list. Can someone help me with this? I am new to Android.

public class EfficientAdapter extends BaseAdapter {
    public EfficientAdapter(Context c) {
        mContext = c;
    }

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

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

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

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView i = new ImageView(mContext);
        i.setImageResource(mImageIds[position]);
        i.setScaleType(ImageView.ScaleType.FIT_END);
        i.setLayoutParams(new ListView.LayoutParams(60, 60));
        return i;
    }

    private Context mContext;
    private Integer[] mImageIds = { R.drawable.video3, R.drawable.video5, R.drawable.music2, };
}

This is my code where I have loaded list of images from an array. Please help me with this code.

  • 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-19T13:50:56+00:00Added an answer on May 19, 2026 at 1:50 pm

    You could do something like

    public View getView(int position, View convertView, ViewGroup parent) 
    {
        // Create a linear layout to hold other views
        LinearLayout oItemViewLayout = new LinearLayout(mContext);
    
        // ImageView
        ImageView i = new ImageView(mContext);
        i.setImageResource(mImageIds[position]);
        i.setScaleType(ImageView.ScaleType.FIT_END);
        i.setLayoutParams(new ListView.LayoutParams(60,60));
    
        // Add ImageView to item view layout
        oItemViewLayout.addView(i);
    
        // TextView
        TextView lblTextView = new TextView(mContext);
        lblTextView.setText(mImageNames[position]);
    
        // Add ImageView to item view layout
        oItemViewLayout.addView(lblTextView);
    
        return oItemViewLayout;
    }
    

    Where you have also defined an array of Strings to hold the names of the images, perhaps like

    private String[] mImageNames = {"title of video3", "video5", "music2",};
    

    It would be even easier if you create a layout for the ListItem and load that to create the view instead

    Create a layout called say “mylistview.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="wrap_content"
        android:orientation="vertical" >
                <ImageView 
                    android:id="@+id/ITEMVIEW_imgImage" 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    />
                <TextView 
                    android:id="@+id/ITEMVIEW_lblText" 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    />
    </LinearLayout>
    

    You could then make the getView() method like this

    public View getView(int position, View convertView, ViewGroup parent) 
    {
        // Create a new view or recycle one if available
        View oItemViewLayout;
        if (convertView == null)
        {
            // New view needs to be created
            oItemViewLayout = (View)LayoutInflater.from(mContext).inflate(R.layout.mylistview, parent, false);
        }
        else
        {
            // Recycle an existing view
            oItemViewLayout = (View)convertView;
        }
    
        // ImageView
        ImageView i = (ImageView)oItemViewLayout.findViewById(R.id.ITEMVIEW_imgImage);
        i.setImageResource(mImageIds[position]);
    
        // TextView
        TextView lblTextView = (TextView)oItemViewLayout.findViewById(R.id.IITEMVIEW_lblText);
        lblTextView.setText(mImageNames[position]);
    
        return oItemViewLayout;
    }
    

    That will not only make life easier by allowing you design the view in XML but it will also be more efficient because you will re recycling views that have gone off screen but are still in memory because you are grabbing the convertView instance when there is one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to load in a bunch of images into a list from a directory...my
I'm trying to load a list of filenames from a text file and then
I have a javascript code, whereby I'm trying to load a list from a
I'm trying to load a list of news from a website, so first I
I am trying to store image sources in an array and then add them
I'm trying to load an XML file with a list of books, I looked
i m trying load UIImages from server asynchronously in UITableViewCell. My code worked fine
When trying to load Microsoft.Xna.Framework.dll from any project, it throws a FileNotFoundException. The specified
Im trying to load a image at runtime in WPF using the following code
I have a task - add round corners to HtmlPanelGrid. Now I am trying

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.