• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get only one restaurant when I press click button one click

 
ahmed abed elaziz
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have app inside it only one activity (main activity) and layout XML of main activity have only
list view .this app get restaurants near from my location and display it in list view
What i need to do is add button to the main activity layout when i press on button get to me list of restaurant item by item
from json file and display it in list view but not display all restaurants in one click but show item by item
every click get restaurant
suppose i have 3 restaurant in json file
when i click on button for first click get me first restaurant
when i click on button for second click get me second restaurant
when i click on button for third click get me third restaurant
How to customize this code to accept get item by item restaurant from json file
My code include class and activity and code is working success
my class is FoursquareVenue

MainActivity.java
 
ahmed abed elaziz
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one help me in this task if possible help me
 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a long post. Can you shorten it to highlight exactly where the issue is?
 
ahmed abed elaziz
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for reply
What found in code above is show all Restaurant items name,city,address
in list view in one activity call main activity
What actually need is to add button in layout main activity and when
press on button for one click show one item
when press click again show another item restaurant
until i get all restaurants from json file
depend on button click listener
if button press 3 time get three restaurant
in case of json file have Restaurants
Meaning i need to customize code above to show every click button one item
 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahmed, i still do not understand what you mean.

Please reply showing just the method that is not doing what you want, or that needs modification. Give example input/output, and explain what it should be doing. With that information, i might be able to help.
 
ahmed abed elaziz
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is function show all
i need to customize to accept show item by item under button
protected void onPostExecute(String result) {
if (temp == null) {

} else {

venuesList = (ArrayList) parseFoursquare(temp);

List listTitle = new ArrayList();

for (int i = 0; i < venuesList.size(); i++) {
listTitle.add(i, venuesList.get(i).getName() + ", " + venuesList.get(i).getCategory() + "" + venuesList.get(i).getCity());
}

myAdapter = new ArrayAdapter(MainActivity.this, R.layout.row_layout, R.id.listText, listTitle);
setListAdapter(myAdapter);
}
}
 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you provide the actual result and your expected result?

I would like to help, but i am no expert in this. I am still learning much of the basics. So, i would like to see a simple code example with the actual and expected results, to help keep it small enough for me to understand. Of course, someone else might jump in to help as well.
 
Paul Clapham
Sheriff
Posts: 21559
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I see so far is this: You have a URL, and you submit that to its website, which returns some data. This is somehow converted into a JSON representation of a list of restaurants. Correct?

Now. Do you want that to do something else? Like return only one restaurant? Or do you want to take the list of restaurants and build a user interface where you can display the restaurants in the list, one at a time?

Or do you want something else entirely? Right now nobody understands your question; you have a big lump of code and a wish-list which might relate to the code in some way, but how?
 
ahmed abed elaziz
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply
Code above working without any problem
and it get list of restaurants near from my location without button
what i need actually is only get one restaurant in list view when click button for first time and when press again show another restaurant
every press click get one restaurant
Example
First click get one restaurant
second click get second restaurant
third click get third restaurant
but not show all when press button for first time
 
Paul Clapham
Sheriff
Posts: 21559
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. So you want some different code which takes that list and displays it one item at a time.

I'm not an Android programmer but some of the others on this thread are, I think, so I will leave that to them.
 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahmed abed elaziz wrote:Thanks for reply
Code above working without any problem
and it get list of restaurants near from my location without button
what i need actually is only get one restaurant in list view when click button for first time and when press again show another restaurant
every press click get one restaurant
Example
First click get one restaurant
second click get second restaurant
third click get third restaurant
but not show all when press button for first time

Oh, now i understand what you want. I have not really done this before, so i am not sure how much i can help. I think you need to use a DataAdapter to control what data is available to be shown.
 
Dave Tolls
Ranch Hand
Posts: 2095
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you want it to male a call for each click, or do you just want it to make the current call for the list and then display one at a time?

If the latter then store the JSON somewhere (my Android is a bit limited) along with the current displayed index and onClick of the button read the next one in and display that.

So I can see three chunks of work there.
1. Store the JSON and an index
2. Handle the onClick event
3. Show a restaurant

Each of which should be fairly simple to look up how to do.
 
ahmed abed elaziz
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I write this lines of code under button but it not working why
can you help me in this code
You could storage the parsed ArrayList, make a global variable for counting the number of times that the button has been clicked.
 
Tim Moores
Bartender
Posts: 3129
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags when posting code of any length. I've added them for you this time, but please remember to use them next time.

"it's not working" is not a useful problem description. What, exactly, were you expecting the code to do, and what, exactly, does it do instead?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic