Forums Register Login

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

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Can any one help me in this task if possible help me
+Pie Number of slices to send: Send
It's a long post. Can you shorten it to highlight exactly where the issue is?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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);
}
}
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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?
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1287 times.
Similar Threads
Android- Parsing Local JSON Data (assets folder) (HELP)
Java class with parameter
url error ,please help
Please Help Error getMenuInflater().inflate(R.menu.main, menu);
Difficulty Setting up JSON Object
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:13:20.