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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:21:31+00:00 2026-06-14T12:21:31+00:00

There is the following adapter: private class RepeatingAdapter extends ArrayAdapter<Repeatable> { private List<Repeatable> items;

  • 0

There is the following adapter:

private class RepeatingAdapter extends ArrayAdapter<Repeatable> {

    private List<Repeatable> items;
    private LayoutInflater inflater;
    private int resource;

        public RepeatingAdapter(Context context, int resource,
                List<Repeatable> items) {
            super(context, resource, items);
            this.items=items;
            this.resource=resource;
            inflater=LayoutInflater.from(context);
        }

        @Override
        public View getView(int position, View view, ViewGroup group) {
            View item=(view==null) ? inflater.inflate(resource, null) : view;
            TextView title=(TextView)item.findViewById(R.id.listItemRepeatingTypeTitle);
            title.setText(items.get(position).getTitle());
            items.get(position).setCommand(new RedRectangleCommand(item));
            Log.e("view", item.toString());
            return item;
        }

        @Override
        public Repeatable getItem(int position) {
            return items.get(position);
        }
}

Please, note, that we create new RedRectangleCommand and send View created to it. So, we also do the following thing:

    repeatingList.setAdapter(new RepeatingAdapter(this, 
        R.layout.list_item_repeating_type, types));
    repeatingList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            ((Repeatable)parent.getItemAtPosition(position)).mark();
        }

    });

Please, note, we execute mark() method for selected item (Mark method for Repeatable executes mark() method for command). All is good. And the last code for command:

private class RedRectangleCommand extends Command {

    private View view;
    public RedRectangleCommand(View view) {
        this.view=view;
    }

        @Override
        public void mark() {
            ImageView image=(ImageView)view.findViewById(R.id.listItemRepeatingTypeImage);
            image.setBackgroundColor(Color.RED);
            image.invalidate();
        }

        @Override
        public void unmark() {
            ImageView image=(ImageView)view.findViewById(R.id.listItemRepeatingTypeImage);
            image.setBackgroundColor(Color.BLACK);
        }       
}

I need to change color of ImageView from selected View by click. But it doesn’t work! Also, my log shows me that selected item and item from Command are different ones. What’s going on?

  • 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-14T12:21:33+00:00Added an answer on June 14, 2026 at 12:21 pm

    Maybe you can try this instead and see if it’s any different. What it does is try to refer to the RedRectangleCommand object directly by making it a method of your custom adapter:

        RepeatingAdapter rAdapter = new RepeatingAdapter(this, 
                R.layout.list_item_repeating_type, types);
    
        repeatingList.setAdapter(rAdapter);
        repeatingList.setOnItemClickListener(new OnItemClickListener() {
    
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
    
                rAdapter.markCommand(position);
            }
    
        });
    

    Then in your adapter:

    private class RepeatingAdapter extends ArrayAdapter {
    
            private List<Repeatable> items;
            private LayoutInflater inflater;
            private int resource;
    
            public RepeatingAdapter(Context context, int resource,
                    List<Repeatable> items) {
                super(context, resource, items);
                this.items=items;
    
                // .... some code
    
            public void markCommand(int position) {
                items.get(position).mark();
            }
        }
    

    Also i think a real issue is that part in your getView:

    items.get(position).setCommand(new RedRectangleCommand(item));
    

    Because as of now, it is making a new one of these objects, re-instantiating, over and over again no-matter if it was used or not, only as long as the listView row disappeared from view and has come back again. You can imagine how wasteful and troublesome it might be especially if trying to refer to a specific instance. there should be several ways around this. For instance, you could only do a setCommand if that Repeater doesn’t have one yet. Maybe make a boolean method to check is it has one of those RedRectangleCommand or something like checking if convertView is null. Another idea i’m trying to make solid is doing some constructor work but needing a parameter of View seems troublesome:

    private View item;
    public RepeatingAdapter(Context context, int resource,
                List<Repeatable> items) {
            super(context, resource, items);
            this.items=items;
            this.resource=resource;
    
            inflater=LayoutInflater.from(context);
            item = inflater.inflate(resource, null);
    
            for (int i = 0; i < items.size; i++) {
                items.get(i).setCommand(new RedRectangleCommand(item));
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following is my ListView adapter. You can see in it that there is a
I have the following class in my program: public class RZoom extends Activity {
In my Android application, I have a simple list view with adapter. There's a
I have a class Data<T> with a generic attribute private T value; is there
Let's say there's following directory structure: root | +--projects | | | +-test |
I need to implement the following: There is a table A which is supposed
I use node.js as REST API. There are following actions available: /contacts, GET, finds
I am reading about closures in Javascript: The Good Parts book. There is following
There is a following function that is supposed to make a comparison between 2
We have the following setting: There is a web application which has a jboss

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.