我有一个测试应用程序,它连接蓝牙并接收和发送数据。这里一切都很好。
我的问题是我需要在设置TextView之前处理返回
如果我收到"好的,"我需要返回"打开"。
如果我收到" OFF",我需要返回"关闭"。
我无法操纵数据。这里有一些提示吗?
我的代码:
void appendLog(){
bluetoothIn = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == handlerState) {
String readMessage = (String) msg.obj;
recDataString.append(readMessage);
int endOfLineIndex = recDataString.indexOf("\r\n");
while ((endOfLineIndex= recDataString.indexOf("\r\n")) > 0){
String dataInPrint = recDataString.substring(0, endOfLineIndex);
txtString.setText(dataInPrint);
Log.d("BT", "Received: " + dataInPrint);
String aux = dataInPrint.toString();
// If i received "OK" I need return in TV "Turn on"
if(aux == "OK"){
Log.d("BT", "OK");
//txtString.setText("Turn on");
}else{
Log.d("BT, "NOK");
//txtString.setText("Turn off");
}
recDataString.delete(0, recDataString.length());
}
}
}
};
}
Android监视器:
07-08 21:06:19.000 29972-29972/com.test D/BT: Received: OK
07-08 21:06:19.000 29972-29972/com.test D/BT: NOK
全力以赴,对不起我的英语;)
答案 0 :(得分:1)
更改if语句以正确比较字符串。
SELECT
id_or_whatever_key_column_you_have,
SUM(column1 CONTAINS ("Test Value")) WITHIN RECORD AS matches
FROM testdata
看到这个SO POST How do I compare strings in Java?