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