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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:09:15+00:00 2026-06-01T00:09:15+00:00

The getView method in my custom ArrayAdapter is getting called multiple times, which I

  • 0

The getView method in my custom ArrayAdapter is getting called multiple times, which I assume it is meant to. Problem is, I have a quantity TextView which is dynamically set but when you scroll and the box goes off screen the value disappears. I am not sure what I am doing wrong and Google is not proving to be much help. Hopefully someone here can help me.

The adapater is called:

adapter = new MenuAdapter(thisActivity, R.layout.menu, list);
setListAdapter(adapter);

My Custom ArrayAdapter:

public MenuAdapter(Context context, int textViewResourceId, ArrayList<Object> menu) {
    super(context, textViewResourceId, menu);
    this.menu = menu;
    vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
          
            Object cat = menu.get(position);
            if (cat.getClass().equals(Category.class)) {
                v = vi.inflate(R.layout.category, null);
                Category item = (Category)cat;
                v.setOnClickListener(null);
            v.setOnLongClickListener(null);
            v.setLongClickable(false);
            
                TextView tt = (TextView) v.findViewById(R.id.category);
                tt.setText(item.getName());      
         
            } else if (cat.getClass().equals(OrderItem.class)) {
                v = vi.inflate(R.layout.menu, null);
                OrderItem orderItem = (OrderItem)cat;
                Item item = orderItem.getItem();
                TextView tt = (TextView) v.findViewById(R.id.title);
                tt.setText(item.getName());   
                
                TextView bt = (TextView) v.findViewById(R.id.desc);
                bt.setText(item.getDescription());
                
                TextView qty = (TextView) v.findViewById(R.id.qty);
                qty.setId(item.getId());
                
                
                ImageButton minus = (ImageButton) v.findViewById(R.id.qtyMinus);
                minus.setTag(item);
                ImageButton plus = (ImageButton) v.findViewById(R.id.qtyPlus);
                plus.setTag(item);          
            }
            
            return v;
    }

The menu layout:

<?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="?android:attr/listPreferredItemHeight"
    android:padding="6dip"
    android:background="#FFFFFF">
        
    <RelativeLayout
        android:orientation="vertical"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="fill_parent"
        android:cacheColorHint="#FFFFFF"
        android:background="#FFFFFF">

        <TextView
            android:id="@+id/title"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:textSize="16px"
            android:textColor="#000000"
        />
        <TextView
            android:id="@+id/desc"
            android:layout_below="@id/title"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textSize="11px"
            android:textStyle="italic"
            android:textColor="#000000"
        />
    </RelativeLayout>
    <ImageButton
    android:id="@+id/qtyMinus"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/minus"
    android:paddingTop="15px"
    android:onClick="minusQty"  />
    <TextView
    android:id="@+id/qty"
    android:layout_width="50px"
    android:layout_height="50px"
    android:textColor="#000000"
    android:textSize="18px"
    android:gravity="center_vertical|center_horizontal"
    android:freezesText="true"
    android:background="@android:drawable/editbox_background"/>
    <ImageButton
    android:id="@+id/qtyPlus"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/plus"
    android:paddingTop="15px"
    android:onClick="addQty" />
</LinearLayout>
  • 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-06-01T00:09:16+00:00Added an answer on June 1, 2026 at 12:09 am

    getView() will be called multiple times as you note. It shouldn’t matter, because your array adapter is based on the state of it’s internal data model (array, list of objects, whatever). getView() should be idempotent in that calling it multiple times shouldn’t change the result.

    You say "when you scroll and the box goes off screen the value disappears". Note sure what mean. When you scroll one of the views generated in getView() off the visible area, and when you scroll it back, the value is different? without any other information, I’d have to say that’s not possible. The reason is again that unless you are modifying the internal state of the adapter, or changing the adapter, you will always generate the same view for a given position.

    By the way, convertView can be null, so you want to do something like,

    View v = convertView;
    if (v == null) {
      v = inflater.inflate(...);
    }
    
    // now use v in the rest of the method
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm getting an error because my Custom ArrayAdapter getView method provides a position
I have one custom ListView called AreasListView which I've included in the XML file.
Hello stackoverflow community, I'm getting a NPE in my getView method of my custom
I am using custom row view in ListView widget. I am having getView method
I have a custom list adapter: class ResultsListAdapter extends ArrayAdapter<RecordItem> { in the overridden
I have a listview with a custom arrayadapter that handles about 15 strings. The
I have a custom baseadapter which does some lazy loading of some images, and
I've created a custom ListView. I've tried to optimize the getView method of my
I have a Gallery, which has an adapter connects to it. In the getView
I know there are few questions regarding this issue of 'getView called few times'

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.