hello, i want to ask how to implement progress bar spinner in background and then stop when parsing JSON data finish to list view. this my source code.
package com.cob.json; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ListView; import android.widget.Toast; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; public class JSONListViewActivity extends Activity { /** Called when the activity is first created. */ //ListView that will hold our items references back to main.xml ListView lstTest; //Array Adapter that will hold our ArrayList and display the items on the ListView ProjectsAdapter arrayAdapter; //List that will host our items and allow us to modify that array adapter ArrayList<Projects> prjcts=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //Initialize ListView lstTest= (ListView)findViewById(R.id.lstText); //Initialize our ArrayList prjcts = new ArrayList<Projects>(); //Initialize our array adapter notice how it references the listitems.xml layout arrayAdapter = new ProjectsAdapter(JSONListViewActivity.this, R.layout.list_item,prjcts); //Set the above adapter as the adapter of choice for our list lstTest.setAdapter(arrayAdapter); //Instantiate the Web Service Class with he URL of the web service not that you must pass WebService webService = new WebService("http:// frontine.hostoi.com/jsontest.json"); //Pass the parameters if needed , if not then pass dummy one as follows Map<String, String> params = new HashMap<String, String>(); params.put("var", ""); //Get JSON response from server the "" are where the method name would normally go if needed example // webService.webGet("getMoreAllerts", params); String response = webService.webGet("", params); try { //Parse Response into our object Type collectionType = new TypeToken<ArrayList<Projects>>() {}.getType(); //JSON expects an list so can't use our ArrayList from the lstart List<Projects> lst= new Gson().fromJson(response, collectionType); //Now that we have that list lets add it to the ArrayList which will hold our items. for(Projects l : lst) { prjcts.add(l); } //Since we've modified the arrayList we now need to notify the adapter that //its data has changed so that it updates the UI arrayAdapter.notifyDataSetChanged(); } catch(Exception e) { Log.d("Error: ", e.getMessage()); } } protected void onListItemClick(ListView lstTest, View v, int position, long id) { // TODO Auto-generated method stub //super.onListItemClick(l, v, position, id); String selection = lstTest.getItemAtPosition(position).toString(); Toast.makeText(this, selection, Toast.LENGTH_LONG).show(); } } -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en