您好我正在尝试从后台线程更新 UI。我正在以编程方式设置单选按钮的选择,但奇怪的是,当我运行应用程序时它不会更新 UI。但是当我逐步调试应用程序时,UI 会自行更新,这对我来说很奇怪。以下是我用来执行此操作的代码。
由于 post runnable 返回一个布尔值,并且它似乎对更新返回 true,但它不会更新 UNI,这很奇怪。
线
_internetConenctivityThread = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try
{
CheckInternetConnectivity(conManager);
Thread.sleep(30000);
}
catch(Exception ex)
{
Log.d("_internetConnectivityThread", "Exception while checking connectivity: " + ex.getMessage());
}
}
});
_internetConenctivityThread.start();
检查方法
private void CheckInternetConnectivity(ConnectivityManager cm)
{
try
{
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected()) {
mParent.connectivity.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// Updating Status Monitor for connectivity
mParent.connectivity.setChecked(true);
}
});
}
else
{
mParent.connectivity.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// Updating Status Monitor for connectivity
mParent.connectivity.setChecked(false);
}
});
}
}
catch(Exception ex)
{
ex.getMessage();
}
}