Monday, June 4, 2012

[android-developers] Foursquare Places JSON data not showing in the list View

I'm trying to parse Foursquare places into android application and i got success as i can view the JSON data in Logcat but listview is not showing any data. 
Here is the code:

public class FoursquarePlacesActivity extends ListActivity {  	  	private ProgressDialog dialog;  	private static final String foursquareClientid="Clientid";  	private static final String foursquareClientsecret="clientsecret";  	  	private static String url="https://api.foursquare.com/v2/venues/explore?ll=24.58,73.68&client_id=" +foursquareClientid + "&client_secret=" +foursquareClientsecret;  	  //JSON Nodes Name that Foursquare will throw  	  	private static final String GROUPS="groups";  	private static final String NAME_TAG = "name";  	  	ArrayList<HashMap<String,String>> venueList;  	  	  	  	@Override  public void onCreate(Bundle savedInstanceState){  super.onCreate(savedInstanceState);  setContentView(R.layout.main);    venueList=new ArrayList<HashMap<String,String>>();    new getPlaces().execute();  	  }  	  	//AsyncTask starts here  	public class getPlaces extends AsyncTask<String, String, String>{    		  @Override  protected void onPreExecute(){  	super.onPreExecute();  	dialog=new ProgressDialog(FoursquarePlacesActivity.this);  	dialog.setMessage("Please wait");  	dialog.setIndeterminate(false);  	dialog.setCancelable(false);  	dialog.show();  }  		  		@Override  		protected String doInBackground(String... args) {  			// TODO Auto-generated method stub  			  			List<NameValuePair> params=new ArrayList<NameValuePair>();  			  			JSONObject json=JSONParser.makeHttpRequest(url,"GET",params);  			JSONArray groups= null;  			Log.d("Inbox JSON:", json.toString());  			  			try{         groups=json.getJSONArray(GROUPS);  				  				//looping all the objects of Groups  				for(int i=0;i<groups.length();i++){  					JSONObject group=(JSONObject)groups.get(i);  					//Editing part (may be incorrect  					JSONArray items=(JSONArray)group.getJSONArray("items");  					  					for (int j=0;j<items.length();j++){  						JSONObject item=(JSONObject)items.get(j);  						//Editing part end  						//Store json item in variable  						String name=item.getString(NAME_TAG);  						HashMap<String,String>map=new HashMap<String, String>();  						  						map.put(NAME_TAG, name);  						  						venueList.add(map);  					}  					    				}			  					    			} catch (JSONException e){  				e.printStackTrace();  			}    			return null;  		}  			  			protected void onPostExecute(String file_url){  				dialog.dismiss();  				  				runOnUiThread(new Runnable(){  					public void run(){  						ListAdapter adapter=new SimpleAdapter(FoursquarePlacesActivity.this, venueList,R.layout.list_item,new String[]{ NAME_TAG },new int[] { R.id.name });    						setListAdapter(adapter);    						ListView lv = getListView();    						// Launching new screen on Selecting Single ListItem  						lv.setOnItemClickListener(new OnItemClickListener(){  								  							  							@Override  						    public void onItemClick(AdapterView<?> parent, View view,  						            int position, long id) {  								  								String name=((TextView)view.findViewById(R.id.name)).getText().toString();	  							}  						});	    					}  				});  			}  			  			  		  	}  	  	  }

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate