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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:22:38+00:00 2026-05-30T04:22:38+00:00

I am developing on Android 2.3.3 (Gingerbread) and I have this particular activity that

  • 0

I am developing on Android 2.3.3 (Gingerbread) and I have this particular activity that displays 50 items in a ListView. The problem is that when the activity is started, the listview doesn’t displays the items properly when I begun scrolling down in the ListView. There are misleading elements of the listview in which the position 12 should display “Title: 12”, “Element: 12” instead of “Title: xx”, “Element: xx”, where xx -> 1 <= xx <= ELEMENT_SIZE. However, when I click on that position it displays the correct element.

The xml and source code are located below.

main.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="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </ListView>

</LinearLayout>

child.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/childTextTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/childTextDetail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

ListViewDebugActivty

public class ListViewDebugActivity extends Activity {

    private final static int ELEMENT_SIZE = 50;
    private ListView listView;
    private List<Element> elements;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        initialize();
        fillListView();
    }

    private void initialize() {     
        listView = (ListView) findViewById(R.id.listView);
        elements = new ArrayList<Element>();
    }

    private void fillListView() {
        final String elementTitle = "Title: ";
        final String elementDetail = "Detail: ";

        for(int index = 0; index < ELEMENT_SIZE; index ++) {
            elements.add(new Element(elementTitle + (index + 1), elementDetail + (index + 1)));
        }

        listView.setAdapter(new ListViewAdapter(this, R.layout.child, elements));
        listView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
                Element element = elements.get(position);
                String message = position + " = " + element.getTitle() + " : " + element.getDetail();
                Toast.makeText(getBaseContext(), message, Toast.LENGTH_LONG).show();
            }
        });
    }

    private class Element {

        private String title, detail;

        public Element(String title, String detail) {
            this.title = title;
            this.detail = detail;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getDetail() {
            return detail;
        }

        public void setDetail(String detail) {
            this.detail = detail;
        }

    }

    private class ListViewAdapter extends ArrayAdapter<Element> {

        private List<Element> objects;
        private TextView childTitle, childDetail;

        public ListViewAdapter(Context context, int layout, List<Element> objects) {
            super(context, layout, objects);
            this.objects = objects;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Element element = objects.get(position);
            if(convertView == null) {
                convertView = getLayoutInflater().inflate(R.layout.child, null);
                childTitle = (TextView) convertView.findViewById(R.id.childTextTitle);
                childDetail = (TextView) convertView.findViewById(R.id.childTextDetail);
            }
            if(element != null && convertView != null) {
                childTitle.setText(element.getTitle());
                childDetail.setText(element.getDetail());
            }

            return convertView;
        }

    }

}

Thanks in advance.

  • 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-30T04:22:39+00:00Added an answer on May 30, 2026 at 4:22 am

    I won’t be lecturing about ViewHolders, but for now, moving your childTitle and childDetail instantiation inside the getView method should fix the problem you’re having.
    If you find that you want more speed and efficiency in your listview, click on the link.

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

Sidebar

Related Questions

I have been developing Android application where I use this code: Date d=new Date(new
I have been developing Android application, and I have one question - ListView uses
I have been developing Android application which has 3 ListView and one ContextMenu for
I am developing Android Application having the listview in an activity . I implemented
I've just started developing Android applications. I'm having a little problem with networking. If
Hi i am developing android application. I that i have creating the dynamic table
I'm developing a sync adapter. I found this: http://groups.google.com/group/android-developers/msg/85f9304dfcc4e284 In that forum a google
I've just started developing android apps and I am wondering about this right from
I'm currently developing an Android application that fetches images using http requests. It would
HI all, I'm just getting started with developing for Android. I'm looking to port

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.