如何显示水平进度条

时间:2013-12-26 10:30:10

标签: android multithreading handler android-progressbar

我想显示水平进度条。在我的代码中,我使用圆形进度条执行此操作。我需要在从文件中搜索文本时显示水平进度条。

    public  void search(){
    pd.setVisibility(View.VISIBLE);

    new Thread(new Runnable() {

        @Override
        public void run() {

            haspmap = Searching(folderNameSelected, langTypeSelected,searchingWord.toLowerCase().trim());

            mHandler.post(new Runnable() {

                @Override
                public void run() {
                    RecordText.setText(Recordsize+ " Results found");
                    //              int d=haspmap.get(resultRefList).size();
                    listAdapter = new MylistAdapter(MainActivity.this,
                            haspmap.get("resultArray"), haspmap.get("suratName"),haspmap.get("ayahnumber"));
                    SurahList.setAdapter(listAdapter);

                    hideKeyboard(inputSearch);
                    inputSearch.setSelection(inputSearch.getText().length());
                    pd.setVisibility(View.GONE);
                    searchedList.setVisibility(View.GONE);
                }
            });

        }
    }).start();
}

3 个答案:

答案 0 :(得分:2)

修改并使用:

int progress_status = 0;

 ProgressDialog progressBar = new ProgressDialog(view.getContext());
                    progressBar.setCancelable(false);
                    progressBar.setMessage("Please Wait...");
                    progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                    progressBar.setProgress(0);
                    progressBar.setMax(100);
                    progressBar.show();
                    new Thread(new Runnable() {
                        public void run() {
                            if(progress_status < 100) {
                                loginUser(num, code);

                                // Update the progress bar
                                handler.post(new Runnable() {
                                    public void run() {
                                        progressBar.setProgress(progress_status);
                                    }
                                });
                            }
                        }
                    }).start();

答案 1 :(得分:2)

答案 2 :(得分:1)

默认情况下,进度条是一个旋转轮(一个不确定的指示器)。要更改为水平进度条,请应用Widget.ProgressBar.Horizo​​ntal样式,如下所示:

<ProgressBar
     style="@android:style/Widget.ProgressBar.Horizontal"
     ... />

请查看此链接。 http://developer.android.com/reference/android/widget/ProgressBar.html