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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:41:30+00:00 2026-06-18T18:41:30+00:00

I have an application with a custom list view which has a textview and

  • 0

I have an application with a custom list view which has a textview and an image(delete), when I click the image the background color of that row should change and when I click the same image again its background should change to default color. I’m able to change the background color but only once, Im not able to change it twice, I mean Im not able to revert back to its default color.

Here is my code …

CustomListView.java

public View getView(final int position, View convertView, ViewGroup parent) {
    holder = null;
    DataFields rowItems = (DataFields) getItem(position);
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

    if (convertView == null) {
        convertView = inflater.inflate(R.layout.home_field_row, null);
        holder = new ViewHolder();
        holder.dataFields = items.get(position);
        holder.mName = (TextView) convertView
                .findViewById(R.id.hmFieldName);
        holder.mDeleteImage = (ImageView) convertView
                .findViewById(R.id.hmFieldDeleteImage);
        holder.mDeleteCheck = (ImageView) convertView
                .findViewById(R.id.hmFieldDeleteCheck);
        holder.mDeleteMainRL = (RelativeLayout) convertView
                .findViewById(R.id.hmFieldMainRL);
        holder.mDeleteImage.setTag(position);

        final View clickView = convertView;
        holder.mDeleteImage
                .setOnClickListener(new ImageView.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        int status = 0;

                        HomeActivity.mDeleteFieldLL
                                .setVisibility(View.VISIBLE);
                        HomeActivity.hmAddField
                                .setVisibility(View.INVISIBLE);

                        holder.dataFields = items.get(position);

                        if (mFieldId.size() == 0) {
                            mFieldId.add(holder.dataFields);
                            ++count;
                            HomeActivity.hmDeleteSelected
                                    .setText("Delete (" + count + ")");

                            clickView.setBackgroundColor(R.color.list_row_bg);

                        } else {
                            for (int i = 0; i < mFieldId.size(); i++) {
                                if (mFieldId.get(i).getId() == holder.dataFields
                                        .getId()) {
                                    status = 1;
                                }
                            }

                            if (status == 0) {
                                mFieldId.add(holder.dataFields);
                                ++count;
                                HomeActivity.hmDeleteSelected
                                        .setText("Delete (" + count + ")");

                                clickView.setBackgroundColor(R.color.list_row_bg);

                            } else if (status == 1) {
                                mFieldId.remove(holder.dataFields);
                                --count;
                                if (count < 0)
                                    count = 0;

                                clickView.setBackgroundColor(R.color.list_row_bg_default); //doesnt changes back to default color

                                HomeActivity.hmDeleteSelected
                                        .setText("Delete (" + count + ")");
                            }
                        }
                    }
                });

        convertView.setTag(holder);
    }

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

    holder.mName.setText(rowItems.getName());

    return convertView;
}

And one more problem is, that background color is not the color I mentioned in color.xml, I tested by putting different colors but when I click the image that color is changing to only one particular color.

So, to put it simple, I need to change the background color of listview row when I click the image and revert back to the default color when I click it again.

Any kind of help is much appreciated. Thanks !

  • 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-18T18:41:31+00:00Added an answer on June 18, 2026 at 6:41 pm

    I think the color may already changed, but you make mistake at setBackgroundColor(), so it seem like the color is not changing.

    For the color problem try using this code

    clickView.setBackgroundColor(context.getResources().getColor(R.color.list_row_bg));
    

    You have to pass Context object when instantiate adapter.

    or you can use something like

    layout.setBackgroundColor(0xFFFFFFFF);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application with a custom list view which has a textview and
I have implemented a Custom List View which displays text along with image. The
In my application i have used list view and custom cell which contain product
We have a web application that has custom errors turned on so that users
I have an application which shows a list view. I am planning to make
I have a Custom ListView in my application and it has some TextView s
I have designed an application with a list-view in which I can change the
I have an AlertDialog in my application. It contains a list of custom views
We have an application (a custom network management tool for building automation) that supports
Well, here is my problem: I have an application that uses a custom Javascript

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.