简体   繁体   中英

How to Get the Next and previous list items from a listview in android

I have a listview Containing some listitems similar to twitter tweets.When i clicked on a particular listitem,it shows the details of the that particular list item.

On that activity,there contains two buttons for showing "next" listitems details and "prev" listitem details.

Problem: How to show the "prev" listitem(by clicking prev button) and "next" listitem(by clicking next button) on that particular activity using view flipper.How can get the Listitem details from the main activity to this activity?

   **Next :**
   int position,last;
   position=listView.getCheckedItemPosition();
   position=position + 1;
   listView.getItemAtPosition(position);
   last=listView.getLastVisiblePosition()
  if(position==last)
     {
       System.out.println("Next is Impossilble");
     }

  **Previous:**
   int position;
   position=listView.getCheckedItemPosition();
   position=position - 1;
   listView.getItemAtPosition(position);
   last=listView.getLastVisiblePosition()
  if(position==1)
     {
       System.out.println("previous is Impossilble");

You need to get the data from the array or arraylist whatever you are using for adapter. Adapter needs either array or list of data while creating. you can store this array or list for further access

Try with the following steps

  • When you select any particular item you are getting position of the item. store this position as a counter variable.
  • Depending on the position you are showing some data in some view.
  • when you click on next button increase the counter
  • Similarly when you click on previous button reduce the counter
  • Use this counter value to get the data from the array or list which is used in listview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM