所以我想显示我的OBD2适配器输入的电压输入。现在我只是在处理程序中将电压显示为textview
,但我希望它能在listview
显示,因为在添加越来越多的数据时更方便
Listview示例:
BTHandler.java
public void run() {
OBDcmds();
try {
ModuleVoltageCommand voltageCommand = new ModuleVoltageCommand();
while (!Thread.currentThread().isInterrupted()) {
guiHandler(Constants.VOLTAGE_STATUS, 0, voltageCommand.getFormattedResult());
try {
voltageCommand.run(mmInStream, mmOutStream);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} catch (Exception e) {...}
}
MainActivity.java
private Handler mHandler = new Handler() {
TextView voltageView = null;
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case Constants.MESSAGE_STATE_CHANGE:
switch (msg.arg1) {
case BTHandler.STATE_CONNECTED:
(...)
socView = (TextView) findViewById(R.id.socView);
break;
case (...)
break;
}
break;
case Constants.VOLTAGE_STATUS:
if (msg.obj != null && voltageView != null) {
voltageView.setText((String) msg.obj);
}
break;
}
}
};