Issue with android layout and progressbar

前端 未结 2 1134
小鲜肉
小鲜肉 2020-12-22 10:51

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 thi

相关标签:
2条回答
  • 2020-12-22 11:30

    Use Async task and progress bar as shown here:

    public void  getrss()
    {
         try{
            class test extends AsyncTask{
    
    
                 TextView tv_per;
                 int mprogress;
    
                Dialog UpdateDialog = new Dialog(ClassContext);
    
                @Override
                protected void onPreExecute() {
                    // 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();
                }
    
    
    
                @Override
                protected void onProgressUpdate(Object... values) {
                    // TODO Auto-generated method stub
                    ProgressBar 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);
                }
    
    
    
                @Override
                protected Object doInBackground(Object... params) {
                    // TODO Auto-generated method stub
                    //your code
    }
    
                    super.onPostExecute(result);
                    UpdateDialog.dismiss();
                }
    
             }
             new test().execute(null);
    
         }
         catch(Exception e)
         {
             e.printStackTrace();
         }
    
    }
    
    0 讨论(0)
  • 2020-12-22 11:44

    You probably want to use AsyncTask.

    0 讨论(0)
提交回复
热议问题