2014-10-28 64 views
-3

我设计的android应用程序,使用android 4.3可以连接蓝牙LE 4.0设备,我想知道rssi,所以我的MainActivity已经获得rssi的值,但只有数字,我尝试让这些数字成为进步百分比,但它不起作用?我怎样才能使用Android的进度条

我获取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){} 
      } 
} 

但诠释进度=的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是字符串,但我不知道如何转化的字符串转换成int?

回答

0

它看起来像你的属性mDeviceRssi包含的字符:

mDeviceRssi = ressi + "db" 

,以后你做:

int progress = Integer.parseInt(mDeviceRSSI); 

无法运作。

+0

我的错误,应该是这样的: – 2014-10-29 01:09:19