Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. How to get only one restaurant when I press click button one click

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

Scheduled Pinned Locked Moved Android
javacomxmljsontutorial
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ahmed_sa
    wrote on last edited by
    #1

    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;

    D 1 Reply Last reply
    0
    • A ahmed_sa

      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;

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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

      A 1 Reply Last reply
      0
      • D David Crow

        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

        A Offline
        A Offline
        ahmed_sa
        wrote on last edited by
        #3

        so that How to customize or modify this code to Read the JSON file once into a container of some sort.by code

        L 1 Reply Last reply
        0
        • A ahmed_sa

          so that How to customize or modify this code to Read the JSON file once into a container of some sort.by code

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I already suggested this in your question below, including the sort of container you might consider to hold the JSON data.

          A 1 Reply Last reply
          0
          • L Lost User

            I already suggested this in your question below, including the sort of container you might consider to hold the JSON data.

            A Offline
            A Offline
            ahmed_sa
            wrote on last edited by
            #5

            Who can help me in customize that please tell me site or forum i will try to ask him

            L D 2 Replies Last reply
            0
            • A ahmed_sa

              Who can help me in customize that please tell me site or forum i will try to ask him

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              See List | Android Developers[^] and android read json - Google Search[^].

              1 Reply Last reply
              0
              • A ahmed_sa

                Who can help me in customize that please tell me site or forum i will try to ask him

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                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

                A 1 Reply Last reply
                0
                • D David Crow

                  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

                  A Offline
                  A Offline
                  ahmed_sa
                  wrote on last edited by
                  #8

                  Yes but im beginner for development in android

                  D 1 Reply Last reply
                  0
                  • A ahmed_sa

                    Yes but im beginner for development in android

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    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

                    A 1 Reply Last reply
                    0
                    • D David Crow

                      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

                      A Offline
                      A Offline
                      ahmed_sa
                      wrote on last edited by
                      #10

                      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

                      D 1 Reply Last reply
                      0
                      • A ahmed_sa

                        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

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #11

                        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 the onClick() 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

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups