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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:48:35+00:00 2026-05-27T22:48:35+00:00

My listview reorders when I scroll through it..this is very confusing. Here’s the custom

  • 0

My listview reorders when I scroll through it..this is very confusing.

Here’s the custom adapter I’m using:

    public class LoadExpenseList extends BaseAdapter{
        List<Expense> expenses;
        Context context;

        public LoadExpenseList(Context context, int textViewResourceId,
                List<Expense> expenses) {
            super();
            this.expenses = expenses;
            this.context = context;
        }

        public View getView(final int position, View convertView, ViewGroup parent){
            //View v = convertView;
            AvailableExpenseView btv;

            if (convertView == null) {
                btv = new AvailableExpenseView(context, expenses.get(position));
            } else {
                btv = (AvailableExpenseView) convertView;
            }           
            btv.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Log.i("Expense_Availables", "Item Selected!!");
                    Intent intent = new Intent(getActivity(), ItemDetailActivity.class);

                    int id = expenses.get(position).getExpenseItemId();
                    intent.putExtra("id", id);

                    startActivity(intent);
                }

            });

            btv.setOnLongClickListener(new OnLongClickListener() {

                @Override
                public boolean onLongClick(View arg0) {
                    // TODO Auto-generated method stub
                    return false;
                }

            });

            registerForContextMenu(btv);

            return btv;
        }

        @Override
        public int getCount() {
            return expenses.size();
        }

        @Override
        public Object getItem(int position) {
            return expenses.get(position);
        }

        @Override
        public long getItemId(int position) {
            return expenses.get(position).getExpenseItemId();
        }

    }
  • 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-27T22:48:36+00:00Added an answer on May 27, 2026 at 10:48 pm

    Because your view (AvailableExpenseView) is constructed with an item, then when the adapter tries to reuse views through convertView, you get a view that is already tied to another item.

    Don’t construct your view with your model item, instead call something like convertView.setExpense(expenses.get(position)).

    ListView will try to reuse views to improve performance. So what will happen is that the first items in the list are displayed with newly created views and later on as you scroll it will try to reuse views previously created giving you the view through convertView. Notice these lines:

            if (convertView == null) {
                // You create a view using the proper item
                btv = new AvailableExpenseView(context, expenses.get(position)); 
            } else {
                // You don't override the item that was previously assigned 
                // when the view was created
                btv = (AvailableExpenseView) convertView;
            }    
    

    If convertView is null you are creating a new view, but you are constructing your view with an item. So let’s say this get called with position 0. You create a view using the expense which is first at the list. Later on, listView wants to get the view for let’s say position 20, and says “ok lets reuse the view that we used for position 0”, so it passes this view as convertView but this view was already created with the item in position 0 and you don’t override this. So you end up using a view that has the first item to represent the 20th item.

    To solve this you can easily do something like this:

            AvailableExpenseView btv;
    
            if (convertView == null) {
                // dont create your view with an item
                btv = new AvailableExpenseView(context);
            } else {
                btv = (AvailableExpenseView) convertView;
            }
    
            // Assign the expense wether it is a newly created view or
            // a view that is reused
            btv.setExpense(expenses.get(position));
    

    Of course you will have to edit AvailableExpenseView and create a setExpense() method to populate your view.

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

Sidebar

Related Questions

I have ListView activity class: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] naziviMolitvi =
listview want to merge two different arraylist into one adapter. i try using the
For my ListView I'm using listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new ModeCallback()); private class ModeCallback implements ListView.MultiChoiceModeListener {
here is my listview <ListView android:layout_width=match_parent android:layout_height=match_parent android:id=@+id/ListView android:fastScrollEnabled=true android:divider=@null style=@drawable/listviewfastscrollstyle ></ListView> This is
I'm using the ListView control (ASP.NET 2008) to show a bunch of lines of
$(#listView object.modal).click(function(){ // Get the ID of the clicked link: var link = $(this).closest(h2).attr(title);
In ListView I can change the divider image using android:divider=image but I want to
listView.setOnItemClickListener(new OnItemClickListener(){ @Override public void onItemClick(AdapterView<?> parent, View viewItem, int position, long arg3) {
I have a custom listview which display an image, textview and radio button. I
I've got some ListView . Each list element is constructed using layout looking like

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.