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 retrieve or get next item from json file when press click button listner

how to retrieve or get next item from json file when press click button listner

Scheduled Pinned Locked Moved Android
jsondatabasecomhelptutorial
10 Posts 3 Posters 1 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

    Hi I make one app have only one activity is main activity and it have button textview linear layout the json file i connect to it is

    public static String URL_GET_Place = "https://api.foursquare.com/v2/venues/search?client\_id=SVIBXYYXOEARXHDI4FWAHXGO5ZXOY204TCF1QJFXQLY5FPV4&client\_secret=BAAJO1KXRWESGTJJGVON4W3WUFHAQDAJPLRIYJJ5OPHFQ5VI&v=20130815&ll=30.1136286,31.3280148&query=resturant";

    what i need is get all items from this file item by item based on three atributes and every click get next item name,id,location when i press the fab button to first time get first item when i press the fab button to second time get second item when i press the fab button to third time get third item when i press the fab button to four time get four item until i get all items in json file based on three attributs id,name,location How i make that by code if possible help me

    D 1 Reply Last reply
    0
    • A ahmed_sa

      Hi I make one app have only one activity is main activity and it have button textview linear layout the json file i connect to it is

      public static String URL_GET_Place = "https://api.foursquare.com/v2/venues/search?client\_id=SVIBXYYXOEARXHDI4FWAHXGO5ZXOY204TCF1QJFXQLY5FPV4&client\_secret=BAAJO1KXRWESGTJJGVON4W3WUFHAQDAJPLRIYJJ5OPHFQ5VI&v=20130815&ll=30.1136286,31.3280148&query=resturant";

      what i need is get all items from this file item by item based on three atributes and every click get next item name,id,location when i press the fab button to first time get first item when i press the fab button to second time get second item when i press the fab button to third time get third item when i press the fab button to four time get four item until i get all items in json file based on three attributs id,name,location How i make that by code if possible help me

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

      ahmed_sa wrote:

      How i make that by code if possible help me

      Exactly what do you need help with, processing the file, responding to button clicks, populating a listview? What code have you put together so far? What is it (not) doing?

      "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:

        How i make that by code if possible help me

        Exactly what do you need help with, processing the file, responding to button clicks, populating a listview? What code have you put together so far? What is it (not) doing?

        "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

        My code is

        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_eating);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

            card1 = (LinearLayout) findViewById(R.id.card\_one);
            card2 = (LinearLayout) findViewById(R.id.card\_two);
            card3 = (LinearLayout) findViewById(R.id.card\_three);
        
            tvTitle1 = (TextView) findViewById(R.id.tv\_title1);
            tvTitle2 = (TextView) findViewById(R.id.tv\_title2);
            tvTitle3 = (TextView) findViewById(R.id.tv\_title3);
        
            tvDetails1 = (TextView) findViewById(R.id.tv\_details1);
            tvDetails2 = (TextView) findViewById(R.id.tv\_details2);
            tvDetails3 = (TextView) findViewById(R.id.tv\_details3);
        
            //adding listeners
            card1.setonclickListener(this);
            card2.setonclickListener(this);
            card3.setonclickListener(this);
        
           // type = getIntent().getIntExtra("type", 1);
        
            FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
            fab.setonclickListener(new View.onclickListener() {
                @Override
                public void onclick(View view) {
        
                    if (count < 3) {
        
                        new GetPlace().execute();
                    }
        
        
        
                }
            });
        }
        
        
        
        
        class GetPlace extends AsyncTask<Void, Void, Void> {
        
            /\*\*
             \* Before starting background thread Show Progress Dialog
             \*/
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                pDialog = new ProgressDialog(EatingActivity.this);
                pDialog.setMessage("Picking an Item...");
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(true);
        

        // pDialog.show();
        }

            /\*\*
             \* Getting product details in background thread
             \*/
            protected Void doInBackground(Void... args) {
        
                // updating UI from Background Thread
                try {
                    // Building Parameters
                    List<NameValuePair> dataList = new ArrayList<NameValuePair>();
                    //dataList.add(new BasicNameValuePair("id", '"' + args\[0\] + '"'));
        
                    // getting product details by making HTTP request
                    // Note that product details url will use GET request
                    JSONObject json = json
        
        A D 2 Replies Last reply
        0
        • A ahmed_sa

          My code is

          protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_eating);
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);

              card1 = (LinearLayout) findViewById(R.id.card\_one);
              card2 = (LinearLayout) findViewById(R.id.card\_two);
              card3 = (LinearLayout) findViewById(R.id.card\_three);
          
              tvTitle1 = (TextView) findViewById(R.id.tv\_title1);
              tvTitle2 = (TextView) findViewById(R.id.tv\_title2);
              tvTitle3 = (TextView) findViewById(R.id.tv\_title3);
          
              tvDetails1 = (TextView) findViewById(R.id.tv\_details1);
              tvDetails2 = (TextView) findViewById(R.id.tv\_details2);
              tvDetails3 = (TextView) findViewById(R.id.tv\_details3);
          
              //adding listeners
              card1.setonclickListener(this);
              card2.setonclickListener(this);
              card3.setonclickListener(this);
          
             // type = getIntent().getIntExtra("type", 1);
          
              FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
              fab.setonclickListener(new View.onclickListener() {
                  @Override
                  public void onclick(View view) {
          
                      if (count < 3) {
          
                          new GetPlace().execute();
                      }
          
          
          
                  }
              });
          }
          
          
          
          
          class GetPlace extends AsyncTask<Void, Void, Void> {
          
              /\*\*
               \* Before starting background thread Show Progress Dialog
               \*/
              @Override
              protected void onPreExecute() {
                  super.onPreExecute();
                  pDialog = new ProgressDialog(EatingActivity.this);
                  pDialog.setMessage("Picking an Item...");
                  pDialog.setIndeterminate(false);
                  pDialog.setCancelable(true);
          

          // pDialog.show();
          }

              /\*\*
               \* Getting product details in background thread
               \*/
              protected Void doInBackground(Void... args) {
          
                  // updating UI from Background Thread
                  try {
                      // Building Parameters
                      List<NameValuePair> dataList = new ArrayList<NameValuePair>();
                      //dataList.add(new BasicNameValuePair("id", '"' + args\[0\] + '"'));
          
                      // getting product details by making HTTP request
                      // Note that product details url will use GET request
                      JSONObject json = json
          
          A Offline
          A Offline
          ahmed_sa
          wrote on last edited by
          #4

          What i need is when click fab button on first time show first item on second time click show second item until it get all items in json file meaning i need to customize code above to show all items not three items but based on fab click every click show item

          L 1 Reply Last reply
          0
          • A ahmed_sa

            What i need is when click fab button on first time show first item on second time click show second item until it get all items in json file meaning i need to customize code above to show all items not three items but based on fab click every click show item

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

            That sounds like the wrong way to do it. Why not use a scrollable view (ListView or similar), populate it with all the items in the json data, and let the user scroll through it as necessary.

            A D 2 Replies Last reply
            0
            • L Lost User

              That sounds like the wrong way to do it. Why not use a scrollable view (ListView or similar), populate it with all the items in the json data, and let the user scroll through it as necessary.

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

              Thank you for reply OK i will try with list view but i need when click fab button retrieve me item by item like scenario i will show I will click fab button to first time it give me first item when click fab to second time it give me second item not show all item when press button what i need actually press button get me item when i press again give me next item until i get all items from json file

              L 1 Reply Last reply
              0
              • A ahmed_sa

                Thank you for reply OK i will try with list view but i need when click fab button retrieve me item by item like scenario i will show I will click fab button to first time it give me first item when click fab to second time it give me second item not show all item when press button what i need actually press button get me item when i press again give me next item until i get all items from json file

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

                I'm not sure why you would want to do that, but I do not suppose it is too difficult. Just make sure that your reference to the JSON data is a class variable so you can access it from any method. You then just need to read the next record every time the button is pressed. Alternatively you could read all the data into some sort of List and use an index value to read each record in turn, and reset the index when you reach the last record.

                1 Reply Last reply
                0
                • L Lost User

                  That sounds like the wrong way to do it. Why not use a scrollable view (ListView or similar), populate it with all the items in the json data, and let the user scroll through it as necessary.

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

                  I agree. :thumbsup:

                  "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
                  • A ahmed_sa

                    My code is

                    protected void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.activity_eating);
                    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

                        card1 = (LinearLayout) findViewById(R.id.card\_one);
                        card2 = (LinearLayout) findViewById(R.id.card\_two);
                        card3 = (LinearLayout) findViewById(R.id.card\_three);
                    
                        tvTitle1 = (TextView) findViewById(R.id.tv\_title1);
                        tvTitle2 = (TextView) findViewById(R.id.tv\_title2);
                        tvTitle3 = (TextView) findViewById(R.id.tv\_title3);
                    
                        tvDetails1 = (TextView) findViewById(R.id.tv\_details1);
                        tvDetails2 = (TextView) findViewById(R.id.tv\_details2);
                        tvDetails3 = (TextView) findViewById(R.id.tv\_details3);
                    
                        //adding listeners
                        card1.setonclickListener(this);
                        card2.setonclickListener(this);
                        card3.setonclickListener(this);
                    
                       // type = getIntent().getIntExtra("type", 1);
                    
                        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
                        fab.setonclickListener(new View.onclickListener() {
                            @Override
                            public void onclick(View view) {
                    
                                if (count < 3) {
                    
                                    new GetPlace().execute();
                                }
                    
                    
                    
                            }
                        });
                    }
                    
                    
                    
                    
                    class GetPlace extends AsyncTask<Void, Void, Void> {
                    
                        /\*\*
                         \* Before starting background thread Show Progress Dialog
                         \*/
                        @Override
                        protected void onPreExecute() {
                            super.onPreExecute();
                            pDialog = new ProgressDialog(EatingActivity.this);
                            pDialog.setMessage("Picking an Item...");
                            pDialog.setIndeterminate(false);
                            pDialog.setCancelable(true);
                    

                    // pDialog.show();
                    }

                        /\*\*
                         \* Getting product details in background thread
                         \*/
                        protected Void doInBackground(Void... args) {
                    
                            // updating UI from Background Thread
                            try {
                                // Building Parameters
                                List<NameValuePair> dataList = new ArrayList<NameValuePair>();
                                //dataList.add(new BasicNameValuePair("id", '"' + args\[0\] + '"'));
                    
                                // getting product details by making HTTP request
                                // Note that product details url will use GET request
                                JSONObject json = json
                    
                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    ahmed_sa wrote:

                    if (!pDialog.isShowing()) { pDialog.dismiss();

                    This seems backward. Why would you dismiss a dialog that is not showing?

                    "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:

                      if (!pDialog.isShowing()) { pDialog.dismiss();

                      This seems backward. Why would you dismiss a dialog that is not showing?

                      "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

                      Thank you for reply i will post my code full in another thread and what i need to do

                      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