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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:01:56+00:00 2026-06-16T18:01:56+00:00

I have a listview , it shows up great, however when I click on

  • 0

I have a listview, it shows up great, however when I click on my “edit” action button, I want the listview to use a different layout resource so that buttons show up beside each item in the list.

layout before: listitem_routine
layout I want after "edit" action button clicked: listitem_routine_edit

heres my code that works:

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_routines);

    datasource = new RoutinesDataSource(this);
    datasource.open();

    List<Routine> values = datasource.getAllRoutines();

    ArrayAdapter<Routine> adapter = new ArrayAdapter<Routine>(this,
        R.layout.listitem_routine, R.id.listitem_routine_name, values);
    setListAdapter(adapter);
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      ArrayAdapter<Routine> adapter = (ArrayAdapter<Routine>) getListAdapter();
      // Handle item selection
      switch (item.getItemId()) {
      case R.id.button_routines_edit:
            // change the list view adapter resource layout to *_edit
            // hide this button and show the "done editing (checkmark)" button
          return true;
      default:
          return super.onOptionsItemSelected(item);
      }
  }

I know that the case for R.id.button_routines_edit works because I made toast when it was clicked. and it was delicious. I since removed that code…

but any ways, how would I go about changing the layout resource when R.id.button_routines_edit is clicked? all the code is there, I just don’t know how to go about changing the layout resource and then obviously updating the listview to display the new row layout…

  • 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-16T18:01:58+00:00Added an answer on June 16, 2026 at 6:01 pm

    Reload the listview with the new resource after clicking the action button as follows.

      @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    
      // Handle item selection
      switch (item.getItemId()) {
      case R.id.button_routines_edit:
             ArrayAdapter<Routine> adapter = new ArrayAdapter<Routine>(this,
        R.layout.listitem_routine_edit, R.id.listitem_routine_name, values);
    
    setListAdapter(adapter);
          return true;
      default:
          return super.onOptionsItemSelected(item);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a ListView that simly shows items on it. I want to load
I have a ListView that shows around 300 items. When something is changed and
I have a ListView that shows a list of names. When you select a
I have to add two columns in a ListView . One column shows different
I'm developing a RSS reader android app. I have a ListView that shows my
I have a WPF ListView inside StackPanel, with Height=Auto. It's great that it does
I have a WPF ListView inside StackPanel, with Height=Auto. It's great that it does
I have ListView that shows data: <ListView android:id=@+android:id/list android:layout_width=fill_parent android:layout_height=wrap_content> </ListView> The headlines is
I have a ListView that shows a list of search results. To make things
i have a listview that shows diferent data from my database. this works perfeclty.

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.