How to get only one restaurant when I press click button one click
-
I have app in side 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 package com.foodsmap_project_app.foodsmap_project_app; public class FoursquareVenue { private String name; private String city; private String category; public FoursquareVenue() { this.name = ""; this.city = ""; this.setCategory(""); } public String getCity() { if (city.length() > 0) { return city; } return city; } public void setCity(String city) { if (city != null) { this.city = city.replaceAll("\\(", "").replaceAll("\\)", ""); ; } } public void setName(String name) { this.name = name; } public String getName() { return name; } public String getCategory() { return category; } public void setCategory(String category) { this.category = category; } } MainActivity.java public class MainActivity extends ListActivity { ArrayList venuesList; final String CLIENT_ID = "SVIBXYYXOEARXHDI4FWAHXGO5ZXOY204TCF1QJFXQLY5FPV4"; final String CLIENT_SECRET = "BAAJO1KXRWESGTJJGVON4W3WUFHAQDAJPLRIYJJ5OPHFQ5VI"; final String latitude = "30.435665153239377"; final String longtitude = "31.3280148"; ArrayAdapter myAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new fourquare().execute(); } private class fourquare extends AsyncTask { String temp;
-
I have app in side 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 package com.foodsmap_project_app.foodsmap_project_app; public class FoursquareVenue { private String name; private String city; private String category; public FoursquareVenue() { this.name = ""; this.city = ""; this.setCategory(""); } public String getCity() { if (city.length() > 0) { return city; } return city; } public void setCity(String city) { if (city != null) { this.city = city.replaceAll("\\(", "").replaceAll("\\)", ""); ; } } public void setName(String name) { this.name = name; } public String getName() { return name; } public String getCategory() { return category; } public void setCategory(String category) { this.category = category; } } MainActivity.java public class MainActivity extends ListActivity { ArrayList venuesList; final String CLIENT_ID = "SVIBXYYXOEARXHDI4FWAHXGO5ZXOY204TCF1QJFXQLY5FPV4"; final String CLIENT_SECRET = "BAAJO1KXRWESGTJJGVON4W3WUFHAQDAJPLRIYJJ5OPHFQ5VI"; final String latitude = "30.435665153239377"; final String longtitude = "31.3280148"; ArrayAdapter myAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new fourquare().execute(); } private class fourquare extends AsyncTask { String temp;
ahmed_sa wrote:
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
Read the JSON file once into a container of some sort. When responding to a button click, read next item from container and add to listview's adapter.
ahmed_sa wrote:
and code is working success
So what's the problem?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
ahmed_sa wrote:
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
Read the JSON file once into a container of some sort. When responding to a button click, read next item from container and add to listview's adapter.
ahmed_sa wrote:
and code is working success
So what's the problem?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
so that How to customize or modify this code to Read the JSON file once into a container of some sort.by code
-
I already suggested this in your question below, including the sort of container you might consider to hold the JSON data.
-
-
Are you a developer? :confused:
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Are you a developer? :confused:
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
But creating, or using, a container (i.e., data structure) to hold data that you download from a JSON file has nothing to do with Android. If the code you've shown is entirely of your making, then you shouldn't be having trouble.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
But creating, or using, a container (i.e., data structure) to hold data that you download from a JSON file has nothing to do with Android. If the code you've shown is entirely of your making, then you shouldn't be having trouble.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
I modify my code above as following I storage the parsed ArrayList, make a global variable for counting the number of times that the button has been clicked. public class MainActivity extends ListActivity { ArrayList venuesList; Button btn; int clickCount; // ArrayList allResults; List shownResults = new ArrayList(); final String CLIENT_ID = "SVIBXYYXOEARXHDI4FWAHXGO5ZXOY204TCF1QJFXQLY5FPV4"; final String CLIENT_SECRET = "BAAJO1KXRWESGTJJGVON4W3WUFHAQDAJPLRIYJJ5OPHFQ5VI"; final String latitude = "30.435665153239377"; final String longtitude = "31.3280148"; ArrayAdapter myAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new fourquare().execute(); btn=(Button) findViewById(R.id.button); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String name = venuesList.get(clickCount).getName(); String cat = venuesList.get(clickCount).getCategory(); String city = venuesList.get(clickCount).getCity(); shownResults.add(name + "," + "cat" + "" + city); clickCount++; myAdapter.notifyDataSetChanged(); new fourquare().execute(); } }); } what is wrong in my code
-
I modify my code above as following I storage the parsed ArrayList, make a global variable for counting the number of times that the button has been clicked. public class MainActivity extends ListActivity { ArrayList venuesList; Button btn; int clickCount; // ArrayList allResults; List shownResults = new ArrayList(); final String CLIENT_ID = "SVIBXYYXOEARXHDI4FWAHXGO5ZXOY204TCF1QJFXQLY5FPV4"; final String CLIENT_SECRET = "BAAJO1KXRWESGTJJGVON4W3WUFHAQDAJPLRIYJJ5OPHFQ5VI"; final String latitude = "30.435665153239377"; final String longtitude = "31.3280148"; ArrayAdapter myAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new fourquare().execute(); btn=(Button) findViewById(R.id.button); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String name = venuesList.get(clickCount).getName(); String cat = venuesList.get(clickCount).getCategory(); String city = venuesList.get(clickCount).getCity(); shownResults.add(name + "," + "cat" + "" + city); clickCount++; myAdapter.notifyDataSetChanged(); new fourquare().execute(); } }); } what is wrong in my code
ahmed_sa wrote:
what is wrong in my code
I don't know, you tell us. What's it (not) doing? What's is (not) supposed to do? Is an exception being thrown? I obviously can't know these things. I do know you don't need to call
notifyDataSetChanged()
since neither the array nor the adapter are changing in theonClick()
method."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles