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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:22:42+00:00 2026-05-16T23:22:42+00:00

I have a ListView with let’s say 5 items. When I click on one

  • 0

I have a ListView with let’s say 5 items. When I click on one of these it automatically start a new activity based on the position of my ListView.

Then, in the new activity, it shows like “1 of 5”.

I have two buttons (back and next) to show 2 of 5 etc, but how should I implement so it loads new content without starting a lot of activites for every “2 of 5”, “3 of 5” etc..? It’s meant to be done this way so the user don’t need to go back to the ListView and then choose the second position..

My current code (From the ListView):

        OnItemClickListener itemListener = new OnItemClickListener() {  
        public void onItemClick(AdapterView<?> parent, View v,
          int position, long rowid) {
            Intent intent = new Intent().setClass(ctx, Details.class);
            Bundle b = new Bundle();
            b.putInt("id", parent.getPositionForView(v));
            intent.putExtras(b);
            startActivity(intent);      
        }
    };

and then a piece of code in Details.java:

       next = (Button)findViewById(R.id.next_button);
       back = (Button)findViewById(R.id.back_button);
       Bundle b = getIntent().getExtras();
       id = b.getInt("id");
       id_header_sum = id+1;
       String string_id = Integer.toString(id_header_sum);
       one_of_all.setText(string_id + " of 5");

                    nextOnClick = new OnClickListener() {
            public void onClick(View arg0) {
                  if(id_header_sum==30){
                   }
               else {

               }
            }
        };

        backOnClick = new OnClickListener() {
            public void onClick(View arg0) {
                   if(id_header_sum==1){
                   }
                   else {

                   }
            }
        };

        next.setOnClickListener(nextOnClick);     
        back.setOnClickListener(backOnClick); 

I don’t want to start a single activity for every detail.

Please tell me if the question is unclear and thanks 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-16T23:22:43+00:00Added an answer on May 16, 2026 at 11:22 pm

    You can try using Application class.

    Base class for those who need to
    maintain global application state.

    You can leave the list of elements there.
    Example:

    // Be careful, the name of this class must be
    // placed in the / said in your manifest
    // <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    //     package="com.something.appname"
    // and be called as the manifest says
    //    <application android:name="YourAppName"
    
    public class YourAppName extends Application {
      private List<Item> mItems;
    
      @Override
      public void onCreate() {
        super.onCreate();
        mItems = getYourItemList();
      }
    
      public List<Item> getItems() {
        return mItems;
      }
    

    }

    Nothing fancy there. Just a getter for the list.

    The Detail Activity can be something like this:

    public class DetailActivity extends Activity {
      private YourAppName mApp;
      private ImageButton mNextButton;
      private ImageButton mBackButton;
      private TextView mTitle;
      private int mIndex;
    
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.your_layout);
        mApp = (YourAppName) getApplication();
    
        /*This index should come from the intent */
        mIndex = 2; 
        getWidgets();
        populateWidgets();
      }
    
      private void getWidgets() {
        mNextButton = (ImageButton)findViewById(R.id.next);
        mTitle = (TextView)findViewById(R.id.title);
        /* other findViewById */
    
        mNextButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
               mIndex++; /*Notice that this will get a NPE.
                         You need to place a better logic here */
               populateWidgets();
            }
        });
      }
    
      private void populateWidgets() {
        Item item = mApp.getItemList().get(mItem);
        mTitle.setText(item.getName());
      }
    }
    

    Some comments about your code:

    Intent intent = new Intent().setClass(ctx, Details.class); looks strange. The common way would be Intent intent = new Intent(ctx, Details.class);

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

Sidebar

Related Questions

No related questions found

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.