我有一个包含在运行时添加的片段的活动。活动也连接到tcp服务器。当我滑动片段服务器时,在另一个线程中发送消息。然后我想更改此线程中片段内的按钮颜色。我已经在下面的片段中编写了代码:
public class changeBtn implements Runnable
{
@Override
public void run() {
button = (Button) fragmentView.findViewWithTag("Button1");
}
}
public void startProg(String[] array)
{
new Thread(new changeBtn()).start();
}
这是在tcp
的活动中工作异步的类 public class connectTask extends AsyncTask<String,String,TCPClient> {
@Override
protected TCPClient doInBackground(String... message) {
//we create a TCPClient object and
mTcpClient = new TCPClient(new TCPClient.OnMessageReceived() {
@Override
//here the messageReceived method is implemented
public void messageReceived(String message) {
//this method calls the onProgressUpdate
srvrMessage = message;
if(srvrMessage!=null&&message!=null) {
acikMasalar = srvrMessage.split("\\*");
mesajGeldi = true;
FragmentMasaDesing fragment=null;
if(mesajGeldi) {
int a =mViewPager.getCurrentItem();
fragment = (FragmentMasaDesing) getSupportFragmentManager()
.getFragments().get(mViewPager.getCurrentItem());
}
if(fragment!=null) {
fragment.startProg();
}
}
}
});
mTcpClient.run();
return null;
}
}
我在活动中运行的线程中运行此代码。它抛出了这个错误:&#34;只有创建视图层次结构的原始线程才能触及它的视图。&#34;
如何更改活动中其他线程的按钮颜色?