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 3963914
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:16:18+00:00 2026-05-20T03:16:18+00:00

I have a ListActivity in which I am trying to display an ImageView under

  • 0

I have a ListActivity in which I am trying to display an ImageView under the List. I’m attempting to do this by creating my own BaseAdapter and using two different methods inside the getView method, one for the List and one for the ImageView. I managed to get the ImageView displayed under the List how I want it, but the problem I am having is the List isn’t displayed correctly.

For some reason any item in the list that isn’t on the screen until the user scrolls down gets populated with the wrong data like so:

----Top Screen------
|     Item 1       |
|     Item 2       |
|     Item 3       |
|     Item 4       |
----Bottom Screen---
|     Item 1       |   <--Items not on the screen show
|     Item 1       |   <--as item 1 once the user scrolls
|     Image View   |   

What it should be is like so:

----Top Screen------
|     Item 1       |
|     Item 2       |
|     Item 3       |
|     Item 4       |
----Bottom Screen---
|     Item 5       |
|     Item 6       |
|     Image View   |

My custom BaseAdapter

    private class MyCustomAdapter extends BaseAdapter {
        private static final int TYPE_ITEM = 0;
        private static final int TYPE_SEPARATOR = 1;
        private static final int TYPE_MAX_COUNT = TYPE_SEPARATOR + 1;

        private ArrayList<HashMap<String,String>> mData = new ArrayList<HashMap<String,String>>();
        private LayoutInflater mInflater;    
        private TreeSet mSeparatorsSet = new TreeSet();

        public MyCustomAdapter() {
            mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        public void addItem(final String header, final String message) {
            HashMap<String,String> item = new HashMap<String,String>();
            item.put(LINE_1, header);
            item.put(LINE_2, message);

            mData.add(item);
            notifyDataSetChanged();
        }

        public void addImageItem() {
            HashMap<String,String> item = new HashMap<String,String>();
            item.put(LINE_1, "");
            item.put(LINE_2, "");

            mData.add(item);
            mSeparatorsSet.add(mData.size() - 1);
            notifyDataSetChanged();
        }

        @Override
        public int getItemViewType(int position) {
            return mSeparatorsSet.contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
        }

        @Override
        public int getViewTypeCount() {
            return TYPE_MAX_COUNT;
        }

        public int getCount() {
            return mData.size();
        }

        public Object getItem(int position) {
            return mData.get(position);
        }

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

        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder vh = null;
            int type = getItemViewType(position);
            System.out.println("getView " + position + " " + convertView + " type = " + type);
            if (convertView == null) {
                vh = new ViewHolder();
                switch (type) {
                    case TYPE_ITEM:
                        convertView = mInflater.inflate(R.layout.instructions_two_row, null);
                        vh.header = (TextView) convertView.findViewById(R.id.instructions_header);
                        vh.message = (TextView) convertView.findViewById(R.id.instructions_message);
                        vh.header.setText((CharSequence) mData.get(position).get(LINE_1));
                        vh.message.setText((CharSequence) mData.get(position).get(LINE_2));
                        break;
                    case TYPE_SEPARATOR:
                        convertView = mInflater.inflate(R.layout.instructions_image, null);
                        vh.imageView = (ImageView) convertView.findViewById(R.id.instuct_image);
                        vh.imageView.setImageDrawable(getResources().getDrawable(R.drawable.instructions));
                        break;
                }
                convertView.setTag(vh);
            }
            else {
                vh = (ViewHolder) convertView.getTag();
            }           
            return convertView;
        }   
    }

    public static class ViewHolder {
        public TextView header;
        public TextView message;
        public ImageView imageView;
    }

Thanks for the help all!

  • 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-20T03:16:19+00:00Added an answer on May 20, 2026 at 3:16 am

    getView recycles views as you scroll. If convertView is not null, you still need to check that it is the correct type and set the correct values on it.

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

Sidebar

Related Questions

I have a list of albums which I got using this: private List<Album> getAlbums()
I have a Contact Activity which is derived from ListActivity, which displays list of
I'm creating a ListActivity. In each list item I have a View I've created
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have a main class which extends Activity which should spawn a ListActivity and
I have a list view which is populated via records from the database. Now
I have an activity which shows some List entries. When I click on a
I have the below code which is suppose to show a list of contact
I have an Android app with a ListActivity in the main view. The list
I have a ListActivity which lists a bunch of things. If you click on

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.