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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:05:52+00:00 2026-06-12T05:05:52+00:00

I want to draw a check mark for the image view I click on

  • 0

I want to draw a check mark for the image view I click on and uncheck the imageview I clicked on before using the following code snip. I store last checked position in mDeviceAdapter. When I try to uncheck old position, the image view always gives null even for the partial visible image view. I am really confused because I thought only invisible one is recycled… Newbie in Android and any comment is appreciated.

    public void CheckableImageView#setChecked(boolean checked) {
    if (mChecked != checked) {
        mChecked = checked;
        invalidate();
    }
}

    mDeviceGallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {

                    CheckableImageView viewToCheck = (CheckableImageView) view;
                    if (!viewToCheck.isChecked()) {
                        int oldCheckedPosition = mDeviceAdapter
                                .getCheckedPosition();
                        mDeviceAdapter.setCheckedPosition(position);
                        View checkedView = mDeviceGallery
                                .getChildAt(oldCheckedPosition);
                        Log.d(TAG, "old position="+oldCheckedPosition + "old view="+checkedView);
                        if (checkedView != null) {
                            ((CheckableImageView) checkedView)
                                    .setChecked(false);
                            Log.d(TAG, "uncheck position="
                                    + oldCheckedPosition);
                        }
                        viewToCheck.setChecked(true);
  • 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-12T05:05:54+00:00Added an answer on June 12, 2026 at 5:05 am

    That’s not the right approach.
    You need to add to your data type a boolean field (i.e mIsChecked).
    On the onItemClick method set the value of that variable to true and keep its INDEX as a member of the adapter. When another item is clicked set the value of that item to true and set the value of the saved one to false (change the value of the datatype in you ArrayList in the INDEX you stored in the previous click).

    Now, in the getView() method, you must have if/else statement. Something like:

    if (item.isChecked())
    {
        checkedView.setChecked(true);
    }
    else
    {
        checkedView.setChecked(false);
    }
    

    Example to the onClick method: (just a general direction)

    if (item.isChecked())
        {
            checkedView.setChecked(false);
            yourList.get(position).setChecked(true);
            yourList.get(mLastCheckedIndex).setChecked(false);
            mLastCheckedIndex = position;
            notifyDataSetChanged();
        }
        else
        {
            //same but opposite.
        }
    

    Hope this helps!

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

Sidebar

Related Questions

I want to draw some Rectangle over a single Image . For example I
I want to draw an area from given points on a map using the
I want to draw an arc using canvas using a gradient fill. How can
I want to draw a stock chart using Google Chart Tools. My self-written webservice
I want to Draw a hyper Link in C# using stringbuilder when i create
I want to draw lat log in every 1 Km interval using service. I
I want to check if the selected rectangle is transparent: spriteBatch.Draw(texture, new Vector2(0, 0),
I m Drawing the image on canvas with this code and it successfully draw
I want to draw rectangle that is only specified percent high of panel im
I want to draw circle, and i want to re size it based on

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.