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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:17:29+00:00 2026-06-10T01:17:29+00:00

I have a ListFragment containing a list of Earthquake objects that populates using a

  • 0

I have a ListFragment containing a list of Earthquake objects that populates using a custom ArrayAdapter. Each element is either ‘highlighted’ or not, depending on whether the magnitude of the earthquake is above a certain value. The problem is that after scrolling, the ‘highlighted’ row colors will be applied to other rows. I suspect this is to do with the caching used in the ListView. How can I prevent this from happening?

Here is the getView method of my EarthquakeArrayAdapter class:

public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.row, parent, false);
    }

    Earthquake quake = mQuakes.get(position);
    if (quake != null) {
        TextView itemView = (TextView) convertView.findViewById(R.id.magnitude);
        if (itemView != null) {
            itemView.setText(quake.getFormattedMagnitude());
            if (quake.getRoundedMagnitude() >= mMinHighlight)
                itemView.setTextColor(Color.RED);
        }
    // Set other views in the layout, no problems here...
    }
    return convertView;
}

And here is my row.xml layout file:

<?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="horizontal" >

    <TextView
       android:id="@+id/magnitude"
       style="@style/ListFont.Magnitude" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/date"
            style="@style/ListFont.NonMagnitude"
            android:gravity="center_horizontal|top"
            android:textSize="18sp" />
        <TextView
            android:id="@+id/location"
            style="@style/ListFont.NonMagnitude"
            android:gravity="center_horizontal|bottom"
            android:textSize="14sp" />
    </LinearLayout>

</LinearLayout>

I’ve watched this video on the ListView widget and I’m considering doing what Adam Powell suggests at the end – dynamically populating & expanding a LinearLayout inside a ScrollView and simply using that. My data is presently bounded between 0 and 30 items (I haven’t yet tested this so don’t know what the performance difference is likely to be). However, those bounds may not always stay the same – so I’d like to solve this, if I could.

  • 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-10T01:17:30+00:00Added an answer on June 10, 2026 at 1:17 am

    If by highlight you mean setting the color on the magnitude TextView then you simply have to revert any changes if the magnitude isn’t the required one:

    if (quake.getRoundedMagnitude() >= mMinHighlight) {
         itemView.setTextColor(Color.RED);
    } else {
         itemView.setTextColor(/*the default color*/);
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an SherlockFragmentActivity that is showing a few tabs. Each tab is ListFragment.
I have a ListFragment with a custom ListAdapter that lazy loads images and displays
I have a ListFragment whose list should diplay the Albums of the device and
i have about 60 fragments ListFragment , now i use each Listfragment with another
I have a ListView in a ListFragment that is populated via a database query.
In my app I have a FragmentActivity that implements ListFragment.OnSelectedListener. The ListFragment uses a
I have a fragment view that needs replacement with another fragment. When the ListFragment
My Custom Adapter that extends SimpleCursorAdapter for my ListFragment does not display the items
I have a ListFragment populated from a Cursor. I have the list background set
I have a Fragment activity that has a ListFragment on the left and a

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.