4

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?

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
KP_
  • 1,854
  • 25
  • 43
  • Have you tried anything? If you have tried than you have to post your code here where you are facing the problem. – himanshu Dec 28 '11 at 12:00
  • I just saved the id of each items in a array from the first activity and tried to access it.But i dont know whether thats the right way. – KP_ Dec 28 '11 at 12:04
  • In that way ,i got the value...But can we achieve this using viewflipper? – KP_ Dec 28 '11 at 12:07
  • After that get the id of the list item whose contents are displaying by the second activity.Store this id as a counter variable.Now by clicking the next button increase the counter and load corresponding content in the second activity and by clicking the pre. button reduce the counter and load the corresponding data. – himanshu Dec 28 '11 at 12:19
  • you can use Intent to get the contents from one activity to another.Get reference from [here](http://www.vogella.de/articles/AndroidIntent/article.html) – himanshu Dec 28 '11 at 12:32
  • Sorry himanshu,i think you didnt understand my problem..No problem,i will explain it.I had a main activity called"Recent posts" .In that there is a listview which shows all the recent posts.And when somebody clicks on that,it goes to second activity ans show the details of that post.On that second activity,there is a nav button to show the next list item(Recent posts).And all these are webservice calls..So cant increment the id of listitem. – KP_ Dec 28 '11 at 12:41

2 Answers2

8
   **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");
  • But in the second activity,how can i get the id of first listview(from the first activity). – KP_ Dec 29 '11 at 04:19
  • @user1119204 In First Activity Bundle bundle=new Bundle(); bundle.putString("wt",position); Intent intent=new Intent(arg1.getContext(),secondActivity.class); intent.putExtras(bundle); startActivityForResult(intent,0); In the second activity Bundle bundle=this.getIntent().getExtras(); String array=bundle.getString("wt"); strs.setText(array); – selvaiyyamperumal Dec 29 '11 at 04:42
  • I used another method like declare a static arraylist in custom adapter class and saved all id's from the json and in the second activity i called that arraylist like "posts.get(position).id where position is passed from the first activity using bundle.Like this i got the value. And once i got the posts id ,i called the second activity using intent and passes that post id through bundle.Is there any other better way? – KP_ Dec 29 '11 at 06:17
  • Another way os passing array of data is by using bundle array Bundle bundle=new Bundle(); bundle.putStringArray("wt", new String[]{str, strs,addr,phone}); Intent intent=new Intent(arg1.getContext(),searchlistitemActivity.class); intent.putExtras(bundle); In second Activity: strs.setText(array[0]); str.setText(array[1]); addr.setText(array[2]); dialers.setText(array[3]); – selvaiyyamperumal Dec 29 '11 at 11:20
3

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
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
  • But the thing is listitems are called using webservice.So cant increment the counter. – KP_ Dec 28 '11 at 11:52