Click here to Skip to main content
15,885,278 members
Home / Discussions / Android
   

Android

 
AnswerRe: Can't Change Android CalendarView to another month Pin
David Crow10-Jun-16 10:03
David Crow10-Jun-16 10:03 
GeneralRe: Can't Change Android CalendarView to another month Pin
Member 1242380510-Jun-16 10:30
Member 1242380510-Jun-16 10:30 
GeneralRe: Can't Change Android CalendarView to another month Pin
David Crow10-Jun-16 10:36
David Crow10-Jun-16 10:36 
QuestionGood ACTIVE Android discussion forum? Pin
Member 1242380510-Jun-16 6:25
Member 1242380510-Jun-16 6:25 
AnswerRe: Good ACTIVE Android discussion forum? Pin
Richard MacCutchan10-Jun-16 6:32
mveRichard MacCutchan10-Jun-16 6:32 
GeneralRe: Good ACTIVE Android discussion forum? Pin
Member 1242380510-Jun-16 6:41
Member 1242380510-Jun-16 6:41 
GeneralRe: Good ACTIVE Android discussion forum? Pin
rosera20-Jun-16 19:55
rosera20-Jun-16 19:55 
QuestionHow to get only one restaurant when I press click button one click Pin
ahmed_sa4-Jun-16 12:04
ahmed_sa4-Jun-16 12:04 
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<foursquarevenue> venuesList;
final String CLIENT_ID = "SVIBXYYXOEARXHDI4FWAHXGO5ZXOY204TCF1QJFXQLY5FPV4";
final String CLIENT_SECRET = "BAAJO1KXRWESGTJJGVON4W3WUFHAQDAJPLRIYJJ5OPHFQ5VI";
final String latitude = "30.435665153239377";
final String longtitude = "31.3280148";
ArrayAdapter <string> myAdapter;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new fourquare().execute();

}
private class fourquare extends AsyncTask<view, void,="" string=""> {

String temp;

@Override
protected String doInBackground(View... urls) {


temp = makeCall("https://api.foursquare.com/v2/venues/search?client_id=" + CLIENT_ID + "&client_secret=" + CLIENT_SECRET + "&v=20130815&ll=30.435665153239377,31.144435908398464" + "&query=resturant");


return "";
}

@Override
protected void onPreExecute() {

}

@Override
protected void onPostExecute(String result) {
if (temp == null) {

} else {

venuesList = (ArrayList<foursquarevenue>) parseFoursquare(temp);

List<string> listTitle = new ArrayList<string>();

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<string>(MainActivity.this, R.layout.row_layout, R.id.listText, listTitle);
setListAdapter(myAdapter);
}
}
}
public static String makeCall(String url) {


StringBuffer buffer_string = new StringBuffer(url);
String replyString = "";


HttpClient httpclient = new DefaultHttpClient();

HttpGet httpget = new HttpGet(buffer_string.toString());

try {

HttpResponse response = httpclient.execute(httpget);
InputStream is = response.getEntity().getContent();


BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(20);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}

replyString = new String(baf.toByteArray());
} catch (Exception e) {
e.printStackTrace();
}

return replyString.trim();
}
private static ArrayList<foursquarevenue> parseFoursquare(final String response) {

ArrayList<foursquarevenue> temp = new ArrayList<foursquarevenue>();
try {


JSONObject jsonObject = new JSONObject(response);


if (jsonObject.has("response")) {
if (jsonObject.getJSONObject("response").has("venues")) {
JSONArray jsonArray = jsonObject.getJSONObject("response").getJSONArray("venues");

for (int i = 0; i < jsonArray.length(); i++) {
FoursquareVenue poi = new FoursquareVenue();
if (jsonArray.getJSONObject(i).has("name")) {
poi.setName(jsonArray.getJSONObject(i).getString("name"));

if (jsonArray.getJSONObject(i).has("location")) {
if (jsonArray.getJSONObject(i).getJSONObject("location").has("address")) {
if (jsonArray.getJSONObject(i).getJSONObject("location").has("city")) {
poi.setCity(jsonArray.getJSONObject(i).getJSONObject("location").getString("city"));
}
if (jsonArray.getJSONObject(i).has("categories")) {
if (jsonArray.getJSONObject(i).getJSONArray("categories").length() > 0) {
if (jsonArray.getJSONObject(i).getJSONArray("categories").getJSONObject(0).has("icon")) {
poi.setCategory(jsonArray.getJSONObject(i).getJSONArray("categories").getJSONObject(0).getString("name"));
}
}
}
temp.add(poi);
}
}
}
}
}
}

} catch (Exception e) {
e.printStackTrace();
return new ArrayList<foursquarevenue>();
}
return temp;

}

}
AnswerRe: How to get only one restaurant when I press click button one click Pin
David Crow4-Jun-16 16:04
David Crow4-Jun-16 16:04 
GeneralRe: How to get only one restaurant when I press click button one click Pin
ahmed_sa4-Jun-16 20:04
ahmed_sa4-Jun-16 20:04 
GeneralRe: How to get only one restaurant when I press click button one click Pin
Richard MacCutchan4-Jun-16 21:11
mveRichard MacCutchan4-Jun-16 21:11 
GeneralRe: How to get only one restaurant when I press click button one click Pin
ahmed_sa5-Jun-16 2:44
ahmed_sa5-Jun-16 2:44 
GeneralRe: How to get only one restaurant when I press click button one click Pin
Richard MacCutchan5-Jun-16 3:25
mveRichard MacCutchan5-Jun-16 3:25 
QuestionRe: How to get only one restaurant when I press click button one click Pin
David Crow5-Jun-16 12:32
David Crow5-Jun-16 12:32 
AnswerRe: How to get only one restaurant when I press click button one click Pin
ahmed_sa6-Jun-16 7:39
ahmed_sa6-Jun-16 7:39 
GeneralRe: How to get only one restaurant when I press click button one click Pin
David Crow6-Jun-16 7:45
David Crow6-Jun-16 7:45 
GeneralRe: How to get only one restaurant when I press click button one click Pin
ahmed_sa12-Jun-16 4:47
ahmed_sa12-Jun-16 4:47 
QuestionRe: How to get only one restaurant when I press click button one click Pin
David Crow13-Jun-16 1:52
David Crow13-Jun-16 1:52 
QuestionAndroid Pin
maymoona4-Jun-16 5:50
maymoona4-Jun-16 5:50 
AnswerRe: Android Pin
David Crow4-Jun-16 16:01
David Crow4-Jun-16 16:01 
QuestionNew beginer to android Pin
hmanhha3-Jun-16 6:51
hmanhha3-Jun-16 6:51 
AnswerRe: New beginer to android Pin
David Crow3-Jun-16 10:28
David Crow3-Jun-16 10:28 
AnswerRe: New beginer to android Pin
Richard MacCutchan3-Jun-16 22:43
mveRichard MacCutchan3-Jun-16 22:43 
AnswerRe: New beginer to android Pin
AkhilSreekar19-Jun-16 9:41
AkhilSreekar19-Jun-16 9:41 
Questionhow to retrieve or get next item from json file when press click button listner Pin
ahmed_sa3-Jun-16 3:05
ahmed_sa3-Jun-16 3:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.