手动使用Android进度 [英] Using the Android ProgressBar manually
本文介绍了手动使用Android进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不需要线程,我只是想增加进度条的值手动通过点击一个按钮。
I don't need threads, I just want to increment the value of the progress bar manually by clicking a button.
下面是XML code
Here's the XML code
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
和在Java文件中我有
And in the Java file I have
ProgressBar pb;
...
pb = (ProgressBar)findViewById(R.id.progressBar1);
pb.setMax(100);
pb.setProgress(0);
现在在一个按钮被点击时调用的方法,我想通过一个递增的进展
Now in a method that is called when a button is clicked, I want to increment the progress by one
public void increment(View view) {
int progress = pb.getProgress();
pb.setProgress(progress++);
}
这会导致程序崩溃。我怎样才能从这样的Java程序控制进度?
This causes the program to crash. How can I control the ProgressBar from the Java program like this?
推荐答案
2的选项:
最终进度PB =(进度)findViewById(R.id.progressBar1);
或
私人进度PB = NULL;
放置,全局变量
这篇关于手动使用Android进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文