我收到此错误消息“无法从Runnable转换为线程”这样就出现了Threat T = new Runnable(r);
这是我的代码......
final String[] texts = new String[]{player, player11, player111}; //etc
final Runnable r = new Runnable(){
public void run(){
for(final int i=0;i<texts.length;i++){
synchronized(this){
wait(30000); //wait 30 seconds before changing text
}
//to change the textView you must run code on UI Thread so:
runOnUiThread(new Runnable(){
public void run(){
TextView t = (TextView) findViewById(R.id.textView1);
t.setText(texts[i]);
}
});
}
}
};
Thread T = new Runnable(r);
T.start();
答案 0 :(得分:2)
您的代码中有错误的行
更改
Thread T = new Runnable(r);
到
Thread T = new Thread(r);
答案 1 :(得分:0)
Thread
实现了Runnable
,而不是相反。
答案 2 :(得分:0)
TextView t;
Handler handler;
int count = 0;
@Override
public void onCreate(Bundle bundle)
{
t = (TextView) findViewById(R.id.textView1);
Handler handler = new Handler();
handler.post(uiUpdater);
}
Runnable uiUpdater = new Runnable()
{
@Override
public void run()
{
count = (count + 1) % texts.length;
t.setText(texts[count]);
handler.removeCallbacks(uiUpdater);
handler.postDelayed(uiUpdater, 30000);
}
};