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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:54:53+00:00 2026-06-01T00:54:53+00:00

I have a listview and each item has a title, some info, and a

  • 0

I have a listview and each item has a title, some info, and a couple ImageViews I’m using as edit/delete buttons. I don’t want to show these “buttons” unless the user selects the row. I can make the “buttons” invisible using:

        DeleteButton.setVisibility(View.INVISIBLE);
        EditButton.setVisibility(View.INVISIBLE);

in my BindView.

I can make the buttons visible in an onListItemClick:

    ImageView DeleteButton = (ImageView) v.findViewById(R.id.button_delete);
    ImageView EditButton = (ImageView) v.findViewById(R.id.button_edit);
    DeleteButton.setVisibility(View.VISIBLE);
    EditButton.setVisibility(View.VISIBLE);

What I can’t do is make the “buttons” invisible when selecting another item or scrolling away.

The closest I found was to do a loop through the listitems in the current view and set them all to invisible before making the selected one visible:

protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    \\loop through all the items and set them back to invisible
    for (int i=0;i<=l.getLastVisiblePosition();i++){
        View vChild = l.getChildAt(i);
        ImageView DeleteButton = (ImageView) vChild.findViewById(R.id.button_delete);
        ImageView EditButton = (ImageView) vChild.findViewById(R.id.button_edit);
        DeleteButton.setVisibility(View.INVISIBLE);
        EditButton.setVisibility(View.INVISIBLE);
    }

    \\set the selected one visible
    ImageView DeleteButton = (ImageView) v.findViewById(R.id.button_delete);
    ImageView EditButton = (ImageView) v.findViewById(R.id.button_edit);
    DeleteButton.setVisibility(View.VISIBLE);
    EditButton.setVisibility(View.VISIBLE);

}

As you can guess…this approach only works if you have a few items.
I thought about adding a field to the SQLite database my list is using to keep track of the button visibility (similar to what you do for checkboxes) but that seemed silly. Please tell me there’s another way.

  • 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-01T00:54:55+00:00Added an answer on June 1, 2026 at 12:54 am

    Another way to do this would be to have an int field in your class that will remember the current position:

    private int current = -1;
    

    then in the onItemCLick() method use that field to hide/show your views:

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
                // if it is the first click ignore this part
        if (current != -1) {
            View last = l.getChildAt(current); // the last one clicked
            last.findViewById(R.id.button1).setVisibility(View.GONE); // kill it
        }
        v.findViewById(R.id.button1).setVisibility(View.VISIBLE);
        current = position; // remember the new clicked position
    }
    

    If you want the views to be gone also when you scroll the list and those views aren’t visible then in the bindView() method add the lines that hide the views:

    //...
    ImageView DeleteButton = (ImageView) view.findViewById(R.id.button_delete); // view is the view that you get as a parameter
    ImageView EditButton = (ImageView) view.findViewById(R.id.button_edit);
    DeleteButton.setVisibility(View.INVISIBLE);
    EditButton.setVisibility(View.INVISIBLE);
    
    //...
    

    When the use scrolls the list all the views will have the Buttons visibility set to GONE and the onItemCLick() logic will work only for visible views.

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

Sidebar

Related Questions

I have a ListView in which each item has a SeekBar. When I update
I have a ListView where each item has a checkbox. Initially there are no
I have a ListView in which each item has a complex layout that contains,
I have a listview with each row containing some text and a delete button.
i have this listview each listview item has a textview that have background ,
I have a ListView with some custom sections in it. Each section has it's
I have a listview with a custom adapter. Each listview item has an ImageView.
I have a listView, where each row has a button in the row layout.
I have a listview with several items that are created dynamically, each has two
I have a ListView with some items. I have toggleButton in each row of

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.