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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:27:40+00:00 2026-05-27T02:27:40+00:00

I made a list such that every time I click on an item, it

  • 0

I made a list such that every time I click on an item, it opens another page. The problem is that if you use the back button, it will close the application. I would rather return to the previous menu instead; how can I fix this?

public class Listview extends Activity {

    static ListView listView;

    static public class BackgroundWorker extends AsyncTask<Void, Person, Void> {
        @SuppressWarnings("unchecked")
        @Override
        protected void onPreExecute () {
            // Prima di iniziare a inserire gli elementi svuotiamo l'adapter
            ( ( ArrayAdapter<Person> ) listView.getAdapter() ).clear();
            super.onPreExecute();
        }

        @Override
        protected Void doInBackground ( Void... params ) {
            Person[] people = { new Person( "Privacy",R.drawable.icon1 ) };
            Person[] people1 = {new Person( "Visualizzazione", R.drawable.icon1 )};
            Person[] people2=  { new Person( "Notifiche", R.drawable.icon1)};

            // riempimento casuale della lista delle persone
            Random r = new Random();

            for ( int i = 0; i < 1; i++ ) {
                // Pubblichiamo il progresso
                publishProgress( people);
                publishProgress( people1);
                publishProgress( people2);
            }

            return null;
        }

        @SuppressWarnings("unchecked")
        @Override
        protected void onProgressUpdate ( Person... values ) {
            // Aggiungiamo il progresso pubblicato all'adapter
            ( ( ArrayAdapter<Person> ) listView.getAdapter() ).add( values[0] );
            super.onProgressUpdate( values );
        }
    }

    @Override
    public void onCreate ( final Bundle savedInstanceState ) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.main );
        listView = ( ListView ) findViewById( R.id.personListView );
        listView.setAdapter( new PersonAdapter( this, R.layout.row_item, new ArrayList<Person>() ) );
        listView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Person p = (Person) parent.getItemAtPosition(position);

                switch(position) {
                    case 0:
                        onCreate1(savedInstanceState);
                        //  setContentView(R.layout.main1);
                        break;
                    case 1:
                        setContentView(R.layout.main2);
                        break;
                    case 2:
                        setContentView(R.layout.main3);
                }
            }
        });
        new BackgroundWorker().execute();
    }
}
  • 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-27T02:27:41+00:00Added an answer on May 27, 2026 at 2:27 am

    Your problem is here:

    switch(position) {
        case 0:
            onCreate1(savedInstanceState);
            //  setContentView(R.layout.main1);
            break;
        case 1:
            setContentView(R.layout.main2);
            break;
        case 2:
            setContentView(R.layout.main3);
    }
    

    You should not use setContentView more than once in an Activity. You should instead be launching a new Activity with startActivity(). This way you have a history of Activities that will be returned through upon pressing Back.

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

Sidebar

Related Questions

I made this bash one-liner which I use to list Weblogic instances running along
I have made a page in which i m using a list to display
I'm working on a problem which requires me to use the STL linked list
I have a menu made of an li list. Each li item needs to
I've got a structure which holds names and ages. I've made a linked-list of
I've created a custom list, and made some changes to the way the CQWP
I have several libraries made by myself (a geometry library, a linked list library,
Say you have a linked list structure in Java. It's made up of Nodes:
I have an Excel spreadsheet containing a list of strings. Each string is made
I have implicitly made this a community wiki seeing that the answers can be

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.