如何在Android中使用进度条

时间:2014-10-28 09:33:52

标签: android progress rssi

我是设计Android应用程序,使用android 4.3可以连接蓝牙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?

1 个答案:

答案 0 :(得分:0)

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

mDeviceRssi = ressi + "db" 

以后再做:

int progress = Integer.parseInt(mDeviceRSSI);

那不起作用。