Jack Smith Jack Smith - 1 year ago 228
Android Question

List item click, on detail activity navigate through next and previous list items from list view activity

I have 2 activities, 1st containing the list view, and when user click on that list view's list item, the detail view activity will be launched (2nd activity).

Now on 2nd activity, I have 2 buttons, NEXT button and PREVIOUS button, so when user click on NEXT button, the next list item from the 1st activity must be shown. And on clicking previous button, the previous list item must be shown.

I have extended ArrayAdapter on 1st activity, to display the custom list item. And on adapter, there are 2 items, i.e. 2 textviews.

And when user clicks and 2nd activity is launched, those 2 textview's details will be shown in detail. And to make the navigation through the items, going back to the 1st activity, and then again 2nd activity is launched per item, that is hectic scenario for user, so I want to navigate the items on detail view activity itself. So what I am supposed to do?

What I have done so far is, I have extended the ArrayAdapter, so from getView() method, I have taken the position value and then on 2nd activity I have done is,

next = (ImageView) findViewById(R.id.next);
previous = (ImageView) findViewById(R.id.previous);

next.setOnClickListener(new OnClickListener() {
public void onClick(View v) {


Log.e("position", String.valueOf(position));


previous.setOnClickListener(new OnClickListener() {
public void onClick(View v) {


Log.e("position", String.valueOf(position));


But I don't know what should I do next?

The position value is taken from 1st activity, with
intent.putExtra("position", position) and fetched on 2nd activity
using intent.getStringExtra("position").

I am not even able to understand this and that , being just theoretical. Thanks in advance.


I have custom ArrayAdapter in 1st activity, and on onclickListener, I have applied,

convertView.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(fActivity.this, sActivity.class);

intent.putExtra("txt1", "name");

intent.putExtra("txt2", "address");

intent.putExtra("position", position);


this position is retrieved from

public View getView(final int position, View convertView, ViewGroup parent) {

this method, is in

class homeAdapter extends ArrayAdapter<list>

as I have written before on this same panel. And now on 2nd activity I have to get
on 2nd activity with next and previous buttons.

Answer Source

You simply just need to do,

in 2nd activity,

str1 = fActivity.listAdapter.getItem(position).data1;
str2 = fActivity.listAdapter.getItem(position).data2;

and in 1st activity,

public static ArrayAdapter<List> listAdapter;

and there you go, you can have your answer.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download