0

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

Jaimin Modi
  • 1,530
  • 4
  • 20
  • 72
  • I don't get your question. – m02ph3u5 Oct 28 '15 at 09:04
  • The issue is..I have a listview showing list items and when any item is clicked..it shows in a detailed view where I also have a previous and next button ..So how do I navigate the listview items from this detailed view activity – PrinceCode Oct 28 '15 at 09:09

2 Answers2

1

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
  • So pls how do yo access the position from the detailed view you are viewing...should the counter be noted from the activity or the adapter ...sake of I have got so many activities performing similiar feature.. – PrinceCode Oct 28 '15 at 09:05
0

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

Pankaj K Sharma
  • 240
  • 1
  • 12