Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6841385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:57:36+00:00 2026-05-26T23:57:36+00:00

Ok Now i admit that i am new to using progress bar infact i

  • 0

Ok Now i admit that i am new to using progress bar infact i never use it but now i need to use it
I have an activity (Main) and a menu which can start 6 new activity. From these activities there is an activity which load the data in a ListView it take 3-4 second to load .This activity parse the json and pass the data to another activity. How can i show the progress bar as soon as user click the menu option for this activity and disappear it when List will be loaded.

Here is the activiy

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
     final Intent intent=new Intent(this ,GetLatAndLng.class);
    setContentView(R.layout.listplaceholder);
    //ProgressBar pb=(ProgressBar)findViewById(R.id.progressbar);
    LocationManager locationManager;
    String context=Context.LOCATION_SERVICE;
    locationManager=(LocationManager)getSystemService(context);

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    String provider = locationManager.getBestProvider(criteria, true);
    Location location = locationManager.getLastKnownLocation(provider);

    final LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
        updateWithNewLocation(location);
        }
        public void onProviderDisabled(String provider){
        updateWithNewLocation(null);
        }
        public void onProviderEnabled(String provider){ }
        public void onStatusChanged(String provider, int status,
        Bundle extras){ }
        };
    updateWithNewLocation(location);
    locationManager.requestLocationUpdates(provider, 2000, 10,
            locationListener);
    double geoLat = location.getLatitute();
    double geoLng = location.getLongitude();
         Bundle b=new Bundle();
    //pb.setVisibility(View.VISIBLE);
    ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();

    JSONObject json = JSONFunction.getJSONfromURL(getUrl());
    Log.v(TAG, "got the json"); 
    try{
        JSONArray  JArray = json.getJSONArray("results");
           Log.v(TAG, "getting results");
        for(int i=0;i<JArray.length();i++){                     
            HashMap<String, String> map = new HashMap<String, String>();    
            JSONObject e = JArray.getJSONObject(i);
            JSONObject location1=e.getJSONObject("geometry").getJSONObject("location");
            latitude[i]=location1.getDouble("lat");
            longitude[i]=location1.getDouble("lng");
            reference[i]=e.getString("reference");
            Log.v(TAG, reference[i]);
            distance[i]=GetLatAndLng.gps2m(geoLat, geoLng,latitude[i] ,longitude[i]); 
            map.put("id",  String.valueOf(i));
            map.put("name", "" + e.getString("name"));
            map.put("vicinity", "Address " +  e.getString("vicinity")+" "+"Disance:"+distance[i]);

            mylist.add(map);                
        }           
    }catch(JSONException e)        {
         Log.e("log_tag", "Error parsing data "+e.toString());
    }
//   pb.setVisibility(View.GONE);
    b.putStringArray("key", reference);
    intent.putExtras(b);
    Log.v(TAG, ""+reference); 
    ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.listview, 
                    new String[] { "name", "vicinity", }, 
                    new int[] { R.id.item_title, R.id.item_subtitle });

    setListAdapter(adapter);
    final ListView lv = getListView();
    lv.setTextFilterEnabled(true);  
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {        
            @SuppressWarnings("unchecked")
            HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);                   
           Toast.makeText(JsonExampleActivity.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_SHORT).show();
            intent.putExtra("clickedid",position);
            startActivity(intent);
        }
    });
}
public void updateWithNewLocation(Location location2) {
    if(location2!=null) {
          double geoLat = location2.getLatitude();
            double geoLng = location2.getLongitude();
    }
}

Thanks in Advance!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:57:36+00:00Added an answer on May 26, 2026 at 11:57 pm

    Use AsyncTask to load data in background while showing loading indicator. In AsyncTask's doInBackground method , process the JSON or anything which is taking time.

    public class HeavyWorker extends AsyncTask < String , Context , Void > {
    
        private ProgressDialog      progressDialog ;
        private Context             targetCtx ;
    
        public HeavyWorker ( Context context ) {
            this.targetCtx = context ;
            this.needToShow = true;
            progressDialog = new ProgressDialog ( targetCtx ) ;
            progressDialog.setCancelable ( false ) ;
            progressDialog.setMessage ( "Retrieving data..." ) ;
            progressDialog.setTitle ( "Please wait" ) ;
            progressDialog.setIndeterminate ( true ) ;
        }
    
        @ Override
        protected void onPreExecute ( ) {
            progressDialog.show ( ) ;
        }
    
        @ Override
        protected Void doInBackground ( String ... params ) {
          // Do Your WORK here
    
           return null ;
        }
    
        @ Override
        protected void onPostExecute ( Void result ) {
            if(progressDialog != null && progressDialog.isShowing()){
                progressDialog.dismiss ( ) ;
            }
        }
    }
    

    In your Activity’s onCreate() execute AsyncTask

    new HeavyWorker().execute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been using Eclipse pretty regularly for several years now, but I admit to
ok, i have to admit that until now i still do not know the
I have installed VSTFS on a machine using the local admin. Now the machine
Now that I know C++ I want to get into desktop application that have
This has bothered me for quite a while, but now it is necessity that
I have a simple django app that is using only the admin. This is
Right now I'm using Doctrine2 in conjunction with Symfony2. I have an entity called
I am new to Wordpress (using roughly 6 months) and just now getting into
I have an application that is using Windows Authentication and a SqlRoleProvider for user
I have a product admin web site that has been generated using ASP.NET Dynamic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.