PrinceCode
PrinceCode

Reputation: 1

Android Next item on listview from second Activity

I have a listview connected to an adapter showing messages but, I am trying to implement next and previous buttons in a different activity.

The problem is how do u show the next or previous item on the listview when a button is clicked from another activity (detailed view activity).

I have entered image description here :

Attached are screen shots of the project with the next and previous buttons

Upvotes: 0

Views: 719

Answers (2)

Pankaj K Sharma
Pankaj K Sharma

Reputation: 230

1 create your arraylist public static which is adapter use like this: public static ArrayList arraylist =new ArrayList<>(); in your class where you are set adapter

2.When you select any item you are getting position of the item from arraylist and store this value in store shared preference.

3.your arraylist from your MainActivity to SecondActivity. like this;

public static ArrayList arraylistSecond=MainActivity.arraylist;

  1. when you click NEXT button get position the position from shared preference and increase position and get item.

  2. and same when you click previous button decrease position and get item

happy coding

Upvotes: 0

user5400869
user5400869

Reputation:

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: 1

Related Questions