繁体   English   中英

如何在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中有一个错误。 在我的班级的公共字符串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);

该代码对我有用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM