-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?
我的錯誤,應該是這樣的: – 2014-10-29 01:09:19