How to get the next and previous list items from a list in android

I have a listview. Contains some lists similar to twitter tweets. When I clicked on a specific list, it shows the details of that particular list item.

There are two buttons in this action to display the "next" list details and "prev" list information.

Problem: How to display the list of "prev" (by clicking the "prev" button) and the "next" listitem (by clicking the next button) in this particular action using flipper. How to get Listitem details from the main activity to this activity?

+4
source share
2 answers

You need to get data from an array or arraylist no matter what you use for the adapter. The adapter needs either an array or a list of data when creating. you can save this array or list for future access

Try the following steps

  • When you select a specific item, you get a position item. save this position as a counter variable.
  • Depending on the position, you display some data in some representation.
  • when you press the next button, increase the counter
  • Similarly, when you click on the previous button, decrease the counter
  • Use this counter value to get data from an array or list that is used in listview
+3
source
**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"); 
+5
source

Source: https://habr.com/ru/post/1388281/


All Articles