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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:26:10+00:00 2026-06-01T05:26:10+00:00

I have a custom listview with three items. One of them is like Add

  • 0

I have a custom listview with three items. One of them is like “Add this to the DB” and when I click to it it inserts something to the DB.

What I want it to do is after doing the insert, change the text to “Delete this from the DB” and also the onClick method to call a method to delete that record instead a method to insert.
Is this possible?

Here is my code:

final String[] opcs = new String[]{"Resultados", "Clasificación", text_fav};

      ArrayAdapter<String> aa = new ArrayAdapter<String>(this, R.layout.list_menutipo_item, opcs);
      m_list.setAdapter(aa);          
      m_list.setOnItemClickListener(new OnItemClickListener() {

          @Override
        public void onItemClick(AdapterView<?> parent, View view,
                  int position, long id) {
                Intent newActivity = null;
                switch( position )
                {                  
                    case 0:  ...


                    case 2:  if (isConnected(m_context))
                     {
                        añadirFavorito();
                     }
                    break;  
                }
            }   
        });    
  • 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-01T05:26:11+00:00Added an answer on June 1, 2026 at 5:26 am

    It’s definitely possible. The view parameter to the onItemClick callback is the view on which you clicked, you can simply change that view’s content. i.e. view.setText("Delete this from the DB").

    Also you will want to distinguish whether the next click is “Add this to the DB” or “Delete this from the DB”, doing a string comparison here like if("Delete this from the DB".equals(view.getText())) might not be of good practice, you can set a flag in the view like view.setTag(true) to indicate that the current view’s content is “Delete this from the DB”. and later you can use view.getTag() to get back the flag to do the comparison.

    Boolean flag = (Boolean)view.getTag();
    if(flag == null || !flag) {
        view.setText("Delete this from the DB");
        flag = true;
        //... code to insert a record to DB
    } else {
        view.setText("Insert this to the DB");
        flag = false;
        //... code to delete a record from DB
    }
    view.setTag(flag);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom listView. The main layout xml is something like this: <?xml
I've a ListView that can have 0 custom items inside (like My Downloads). Is
I have used custom listview and custom rating bar. If I add that custom
I have a custom ListView with two button and I when I click either
I have a ListView with a hundred items that scrolls fine. I added one
Hello I have a multi choice listview. I would like to add more than
I have a list view with several ToggleButton items. When I click one, another
Basically, I have a custom ListView in which each item looks like: <LinearLayout> <Table>
I have ListView with custom Adapter which supplies View to ListView in this way:
I have a ListView of items with checkboxes. I have a custom CursorAdapter that

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.