【发布时间】:2018-02-15 16:08:16
【问题描述】:
我有一个已更新的 TextView,但在我最小化并重新打开应用程序之前我看不到刷新。这是执行该操作的代码。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bleAdapter = ((BluetoothManager) getSystemService(BLUETOOTH_SERVICE)).getAdapter();
Set<BluetoothDevice> pairedDevices = bleAdapter.getBondedDevices();
for (BluetoothDevice device : pairedDevices) {
device.connectGatt(this, true, new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
TextView state;
switch (newState) {
case BluetoothProfile.STATE_CONNECTED:
state = (TextView)findViewById(R.id.state);
state.setText("Connected = True");
state.setTextColor(Color.GREEN);
break;
case BluetoothProfile.STATE_DISCONNECTED:
state = (TextView)findViewById(R.id.state);
state.setText("Connected = False");
state.setTextColor(Color.RED);
break;
}
}
});
}
}
我需要什么来刷新那个 TextView?我做错了什么?
【问题讨论】:
-
你确定
onConnectionStateChange被解雇了吗?在该方法中的某处放置一个断点,看看它是否命中? -
是的,它成功了。因为如果我最小化并重新打开 textView 更新的应用程序。
-
我的意思是在应用程序运行时。
-
是的,我现在已经对其进行了测试,并且它在应用程序运行时命中。
-
为您的案例干杯(连接与否)。也许你会意识到这不是电视问题。