Skip to content Skip to sidebar Skip to footer

Issue With Android Layout And Progressbar

I'm still working on my application that has to store RSS data localy. So far i managed to create a local database and parse the online RSS feed. I also managed to put this inform

Solution 1:

Use Async task and progress bar as shown here:

publicvoidgetrss()
{
     try{
        classtestextendsAsyncTask{


             TextView tv_per;
             int mprogress;

            DialogUpdateDialog = newDialog(ClassContext);

            @OverrideprotectedvoidonPreExecute() {
                // TODO Auto-generated method stub
                mprogress = 0;

                UpdateDialog.setTitle(getResources().getString(R.string.app_name));
                UpdateDialog.setContentView(R.layout.horizontalprogressdialog);
                TextView dialog_message =  (TextView)UpdateDialog.findViewById(R.id.titleTvLeft);
                tv_per = (TextView)UpdateDialog.findViewById(R.id.hpd_tv_percentage);
                dialog_message.setText(getResources().getString(R.string.dialog_retrieving_data));
                dialog_message.setGravity(Gravity.RIGHT);
                UpdateDialog.setCancelable(false);
                UpdateDialog.show();
                super.onPreExecute();
            }



            @OverrideprotectedvoidonProgressUpdate(Object... values) {
                // TODO Auto-generated method stubProgressBar update = (ProgressBar)UpdateDialog.findViewById(R.id.horizontalProgressBar);
                update.setProgress((Integer) values[0]);
                int percent =  (Integer) values[0];
                if(percent>=100)
                {
                    percent=100;
                }
                tv_per = (TextView)UpdateDialog.findViewById(R.id.hpd_tv_percentage);
                 tv_per.setText(""+percent);
            }



            @OverrideprotectedObjectdoInBackground(Object... params) {
                // TODO Auto-generated method stub//your code
}

                super.onPostExecute(result);
                UpdateDialog.dismiss();
            }

         }
         newtest().execute(null);

     }
     catch(Exception e)
     {
         e.printStackTrace();
     }

}

Solution 2:

You probably want to use AsyncTask.

Post a Comment for "Issue With Android Layout And Progressbar"