如何在 Android Studio 中将字符串值传递给 ProgressBar?
how do I pass string value to ProgressBar in Android Studio?
pBar = (ProgressBar) findViewById(R.id.progressBaradmin);
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
while (pStatus <= 100) {
handler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
pBar.setProgress(pStatus);
}
});
try {
// Sleep for 200 milliseconds.
// Just to display the progress slowly
if (pStatus == str1) {
Thread.sleep(90000000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
pStatus++;
}
}
}).start();
我在 str1 中有一个错误。在我的 class 中的 public string str1 中提到了它。如何清除此错误?
如何在 Android Studio 中将字符串值传递给 ProgressBar?
需要先转换str1的类型:
if (Integer.parseInt(str1) == pStatus)
{
// Your code
}
pBar = (ProgressBar) findViewById(R.id.progressBaradmin);
int d = Integer.parseInt(str2);
pBar.setProgress(d);
这段代码对我有用
pBar = (ProgressBar) findViewById(R.id.progressBaradmin);
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
while (pStatus <= 100) {
handler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
pBar.setProgress(pStatus);
}
});
try {
// Sleep for 200 milliseconds.
// Just to display the progress slowly
if (pStatus == str1) {
Thread.sleep(90000000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
pStatus++;
}
}
}).start();
我在 str1 中有一个错误。在我的 class 中的 public string str1 中提到了它。如何清除此错误?
如何在 Android Studio 中将字符串值传递给 ProgressBar?
需要先转换str1的类型:
if (Integer.parseInt(str1) == pStatus)
{
// Your code
}
pBar = (ProgressBar) findViewById(R.id.progressBaradmin);
int d = Integer.parseInt(str2);
pBar.setProgress(d);
这段代码对我有用