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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:51:01+00:00 2026-05-16T17:51:01+00:00

When my list view using a BaseAdapter goes off the screen, each row no

  • 0

When my list view using a BaseAdapter goes off the screen, each row no longer maintains a consecutive position. I don’t know how else to explain it other than this.

If my BA/LV shows 4 items on the screen, and I add a view that displays a TextView of each row, it shows 0,1,2,3 for the row numbers (which is correct). But as soon as I scroll the list down to the bottom 4 items (items 5-8) it then shows those as 4,5,0,1?? Why?

EDIT:
I did discover that if I change

rv = (RowView) convertView;

to

rv =  new RowView(mContext,(cursor.getString(2)),
                        (cursor.getString(5)),
                        cursor.getString(cursor.getColumnIndex(DBHelper.KEY_IMAGEFILENAME)),
                        cursor.getString(cursor.getColumnIndex(DBHelper.KEY_CITY)),position);

it works, but then it is not re-using the code. So, I guess I am on the right track. I did try some convenience methods, but that did not help me too much because I needed to set those values before the Constructor fired off. Do I need to create a new method and fire that at the end? Such as addRow method? This also causes it to scroll VERY Slow.

          @Override
               public void onCreate(Bundle bundle)
               {
                 super.onCreate(bundle);
                 //setContentView(R.layout.findlist);
                 //getListView().setEmptyView(findViewById(R.id.empty));
                 mDbHelper = new DBHelper(this);
                 mDbHelper.open();
                 cursor = mDbHelper.fetchAllLocations();
                 startManagingCursor(cursor);
                 mAdapter = new myListAdapter(this);
                 setListAdapter(mAdapter);
        
               }
    public class myListAdapter extends BaseAdapter {
            public String testing;
            public myListAdapter(Context c) {
                mContext = c;
                // TODO Auto-generated constructor stub
            }
    
            @Override
            public int getCount() {
                // TODO Auto-generated method stub
                return cursor.getCount();
            }
    
            @Override
            public Object getItem(int position) {
                // TODO Auto-generated method stub
                return position;
            }
    
            @Override
            public long getItemId(int position) {
                // TODO Auto-generated method stub
                return position;
            }
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
    
                
                 cursor.moveToPosition(position);
                 RowView rv;
    
    
                 if (convertView == null) {
                        rv = new RowView(mContext,(cursor.getString(2)),
                                (cursor.getString(5)),
                                cursor.getString(cursor.getColumnIndex(DBHelper.KEY_IMAGEFILENAME)),
                                cursor.getString(cursor.getColumnIndex(DBHelper.KEY_CITY)),position);
                    } else {
                        rv = (RowView) convertView;
                        try {
              // I KNOW THIS SECTION IS NOT RIGHT, BUT I HAVE BEEN MESSING IN HERE          
                        rv.setAddress(cursor.getString(2));
                        rv.setCity(cursor.getString(5));
                        rv.setFocusable(true);
                        rv.setClickable(true); }
                        catch (Exception e) {
                            rv = (RowView) convertView;
                            rv.setAddress(cursor.getString(2));
                            rv.setCity(cursor.getString(5));
                            rv.setFocusable(true);
                            rv.setClickable(true); 
                            Toast mToast;
                            mToast = Toast.makeText(FindList.this, "Error :" + e.toString() ,
                                    Toast.LENGTH_LONG);
                            mToast.show();
                        }
                    }
                    
                 return rv;
            }
            
            public void addItems() {
    
                 //String[] from = new String[] { DBHelper.KEY_BUSINESSNAME, DBHelper.KEY_ADDRESS, DBHelper.KEY_CITY, DBHelper.KEY_GPSLONG, DBHelper.KEY_GPSLAT,  DBHelper.KEY_IMAGEFILENAME  + ""};
                 // create array of values of widgits
                 //to = new int[] { R.id.businessname, R.id.address, R.id.city, R.id.gpslong, R.id.gpslat, R.id.preview};
                 // Now create an array adapter and set it to display using our row from notes_row.xml
                 
                 
            }
            
            
            
        }


private class RowView extends LinearLayout {
        private TextView mAddress;
        private TextView mCity;
        public ImageView mArrow;
        public ImageView mPicture;
        public String mPathName;
        public String mDateTime;
        public RowView(Context context, String title, String words, String pathName, String city, int position) {
            super(context);

            this.setOrientation(HORIZONTAL);
            this.setVerticalGravity(16); //CENTER_VERTICAL 

            // Here we build the child views in code. They could also have
            // been specified in an XML file.
           
            //DISPLAY DELETE BUTTON
            Button mButton = new Button(context);
            mButton.setFocusable(false);
            mButton.setId(position);
            mButton.setBackgroundResource(R.drawable.delete3);
            addView(mButton, new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            
            TextView mTitle;
            mTitle = new TextView(context);
            mTitle.setText(Integer.toString(position));
            addView(mTitle, new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

            this.setOrientation(HORIZONTAL);      
            
            try {
             Bitmap bm = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(cursor.getString(cursor.getColumnIndex(DBHelper.KEY_IMAGEFILENAME))),100, 100, true);
                mPicture = new ImageView(context);
                mPicture.setImageBitmap(bm);    
           } catch (Exception e) { 
                 mPicture = new ImageView(context);
                 mPicture.setImageResource(R.drawable.noimage);
           }     
            
            addView(mPicture, new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            
            mArrow = new ImageView(context);
            mArrow.setBackgroundResource(R.drawable.arrowleft3);
            addView(mArrow, new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
          
            currentPosition = position;
            Button button = (Button)findViewById(position);
            button.setOnClickListener(mCorkyListener);
            
        }
  • 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-16T17:51:02+00:00Added an answer on May 16, 2026 at 5:51 pm

    When using the convertView, you are given a view which has been previously used but which is not displayed anymore. You should take care of resetting ALL its attributes with the value of the current item. Otherwise, all the values you have set in the RowView constructor will be kept with the value you gave to this view the first time you created it.

    To better understand ListViews, you have to understand that it only uses a limited set of RowViews, just the number that is enough to fill the display and a few more that will be filled with your data just before having to display them.

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

Sidebar

Related Questions

I have a list view with 2 buttons on each row. I am using
I am using a list view and an adapter for loading a list,each list
I wanted to generate a list view using below code. But after running this
I have created navigaton view using Sencha touch 2. Navigation view has list component
I am creating a app in android. In that i am using list view.
I am using a list view in Android 1.5 to show a list of
Right now I am using a custom list view and I am inflating an
here i am using an activity in which there is a list view,which I
I'm trying to create a page by using view 2. This page list all
We have created custom listview by using the Base adapter. List view contains Text

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.