KP_
KP_

Reputation: 1866

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?

Upvotes: 4

Views: 6937

Answers (2)

selvaiyyamperumal
selvaiyyamperumal

Reputation: 333

   **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");

Upvotes: 8

Sunil Kumar Sahoo
Sunil Kumar Sahoo

Reputation: 53657

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

Upvotes: 3

Related Questions