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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:50:25+00:00 2026-05-24T19:50:25+00:00

I am binding an XML document to a custom adapter. All of the items

  • 0

I am binding an XML document to a custom adapter. All of the items in the list initially have a font color of white. One of the nodes in the XML document has an attribute that I am checking and if the attribute is set, I’d like to change the font color of that item in the ListView to a darker color. The code I have seems to work initially, but if I scroll the list up and down, the items in the ListView that should stay white, change automatically to the dark color, for some reason:

Here is my layout code:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
 android:orientation="vertical">
 <TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/text"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:textSize="15dip" 
    android:textColor="#ffffff"
    android:textStyle="bold"
    android:padding="5px"
     />
 </LinearLayout>

and here is my custom adapter:

 private class CustomAdapter extends BaseAdapter 
 {       
    private ArrayList<FilterItem> mData = new ArrayList<FilterItem>();
    private LayoutInflater mInflater;

    public CustomAdapter() {
        mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public void addItem(FilterItem item) {
        mData.add(item);
    }

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

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

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder;
        FilterItem item = (FilterItem)this.getItem(position);

        if (convertView == null)
        {

            holder = new ViewHolder();

            convertView = mInflater.inflate(R.layout.main, null); 
            holder.text = (TextView)convertView.findViewById(R.id.text);

            convertView.setTag(holder);

        } else {
            holder = (ViewHolder)convertView.getTag();
        }

            TextView tvText = holder.text;

            tvText.setText(item.getTitle());

            if (item.Read())
            {
                tv.setTextColor(Color.Gray);
            }

        return(convertView);
    }
}
  • 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-24T19:50:25+00:00Added an answer on May 24, 2026 at 7:50 pm

    ListView reuses view, as you can see in getView you get convertView, and you only change color from white to gray. You never restore color back to white. I suggest

    if (item.Read()) {
        tv.setTextColor(Color.Gray);
    } else {
        tv.setTextColor(Color.White);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this construct to questionate my xml-document with a binding in xaml. XPath=/doc/B/lists/entry[@value=(/doc/A/selectedValue)]
You can use XPath if you're binding the XML document in the XAML, but
I want to use data binding with an XML document to populate a simple
I have warnings in binding xml files: No grammar constraints (DTD or XML schema)
I have a ASP.Net TreeView control that I am binding to an XML data
I have created an XML schema (foo.xsd) and used xjc to create my binding
Im creating a dynamic MenuBar from xml file, and binding events to menu items
I have a xml document that has a record set like this. <document> <row>
Is there a way to generate an XSD document automatically from the binding.xml used
I have a WPF app that binds a DataGrid to an XML document using

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.