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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:30:52+00:00 2026-05-26T06:30:52+00:00

I know there are lots of threads with more or less same topic but

  • 0

I know there are lots of threads with more or less same topic but none of them covers my situation:

I am populating my ListView with a custom CursorAdapter by using my custom rows. I have two states for the ListView: The first state consists of only texts in the rows; the second state has a delete button in every row. The switch between two states is a button at the bottom of the view.

What I try to achieve is: In first state, when I click on the row, the screen should switch to another view. In second state, when I click on delete button the selected row should be deleted from database, the ListView should be repopulated, and nothing should happen if I press on any other part of the row other than delete button.

I know how to delete an item and repopulate the ListView afterwards and I know how to switch to another view when I click on the row in first state; but I could not combine the two. I am using following method to get the id and position of the row:

protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
     //Code goes in here either for deleting or switching into another view
}

I tried to use some if statements to get the condition for delete button clicked or for row clicked but it did not work.

The first question is obvious: How can I make it work?

The second question is: In second state when any part of the row is pressed other than delete button screen switches to the other view. How can I prevent this? I tried to set .setClickable, .setPressed, .setSelected attributes of the row to false but it did not help.

Thank you for your responses in advance.

  • 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-26T06:30:53+00:00Added an answer on May 26, 2026 at 6:30 am

    In second state when any part of the row is pressed other than delete button screen switches to the other view. How can I prevent this?

    Simply have a listener for the deleteButton

       @Override
        public View getView(int position, View convertView, ViewGroup parent) 
        {
            View row = null;
            LayoutInflater inflater = getLayoutInflater();
    
            row = inflater.inflate(R.layout.one_result_details_row, parent, false);
    
            // inflate other items here : 
            Button deleteButton = (Button) row.findViewById(R.id.Details_Button01);
             deleteButton.setTag(position);
    
            deleteButton.setOnClickListener(
                new Button.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Integer index = (Integer) view.getTag();
                        items.remove(index.intValue());  
                        notifyDataSetChanged();
                    }
                }
            );
    

    In the getView() method you tag the ListItem to postion

    deleteButton.setTag(position);
    

    Convert the getTag() Object to an Integer

    In the OnClickListener() you then delete the item

     items.remove(index.intValue());  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there are lots of questions related to Custom ListView with CheckBox but
I know that there are lots of examples out there on this, but they
I know there have been a few threads on this before, but I have
I've seen a couple similar threads to this question, but none of them really
I know there are lots of solutions for chained dropdown lists but i'm trying
Folks, I know there have been lots of threads about forcing the download dialog
I know there are lots of question like this. But I don't want to
I know there are lots of questions about background images but I'm looking for
I know there are lots of truncate scripts out there, but I can't use
I know there are lots of design patterns (facade, singleton, decorator, etc...) but I'm

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.