【问题标题】:How can I use progressbar in Android如何在 Android 中使用进度条
【发布时间】:2014-10-28 09:33:52
【问题描述】:

我正在设计一个使用android 4.3的android应用程序可以连接蓝牙LE 4.0设备,我想知道rssi,所以我的MainActivity已经得到了rssi的值,但只有数字,我试图让这些数字成为进度百分比,但它不起作用?

我的获取rssi的价值函数:

public void run(){
          int realRssi = rssi+100;
          mDeviceRssi = ressi + "db" ;
          mDeviceRssiView.setText(mDeviceRssi);
}

现在,这是我的问题:

public class sending_thread extends Thread{
              public void run(){
                      try{
                             while(true){
                                    int progress = Integer.parseInt(mDeviceRSSI);
                                    int[] int_progress = new int[1];
                                    int_progress[0] = progress;
MainActivity.handler.sendMessage(MainActivity.handler.obtainMessage(1,int_progress));
                                    Thread.sleep(1000);
                              }
                      }
                      catch(Exception e){}
           }
}

但是 int progress = Integer.parseInt(mDeviceRSSI) 不起作用。

private void seekCircle(){
        SeekCircle seekCircle = (SeekCircle) findViewById(R.id.seekCircle);
        try{
             handler = new Handler() {
               public void handleMessage(Message msg) {
                   super.handleMessage(msg);
                   switch (msg.what) {
                         case 1:
                          int[] receive_obj = (int[]) msg.obj;
                          updateText(receive_obj[0]);
                          break;
                   }
              }
          };
         }catch (Exception e) {
            Log.d("Handler exception", e.toString());
         }
    send_thread = new sending_thread();
    send_thread.start();
}

这是我的错误,代码应该是这样的:

mDeviceRSSI = rssi + " db";
mDeviceRssiView.setText(mDeviceRSSI);

int progress = Integer.parseInt(mDeviceRSSI); //error
int[] int_progress = new int[1];
int_progress[0] = progress;

我知道mDeviceRSSI是String,但是不知道怎么把String转成int?

【问题讨论】:

    标签: android progress rssi


    【解决方案1】:

    您的属性mDeviceRssi 似乎包含字符:

    mDeviceRssi = ressi + "db" 
    

    然后你会这样做:

    int progress = Integer.parseInt(mDeviceRSSI);
    

    这不行。

    【讨论】:

    • 我的错,应该是这样的:
    猜你喜欢
    • 1970-01-01
    • 2011-01-02
    • 1970-01-01
    • 2011-06-10
    • 1970-01-01
    • 1970-01-01
    • 2012-03-20
    相关资源
    最近更新 更多