![](/img/trans.png)
[英]I want to display the contents of that specific text view when i click on the text view on a different activity. I
[英]When I click on the activity I have 3 Text View in that. I want to load the Text View one after another like after a gap of 2 seconds?
我不确定,但是我的研究促使我得出了这一点。 我想我需要创建Thread对象,然后可以使用Thread.sleep(seconds);
但是我不确定它如何与文本视图一起使用。
private void runThread() {
new Thread() {
public void run() {
int i = 0;
while (i++ < 2) {
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView tv1 = (TextView) findViewById(R.id.tvFirst);
TextView tv2 = (TextView) findViewById(R.id.tvSecond);
TextView tv3 = (TextView) findViewById(R.id.tvThird);
}
});
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
}
这甚至没有回应。 我知道我在这里做错了,但这就是我现在能想到的。 任何帮助将不胜感激。
使用Handler.postDelayed 。 例:
new Handler().postDelayed(new Runnable(){
@Override
public void run(){
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView tv2 = (TextView) findViewById(R.id.tvSecond);
tv2.setText("I set this text after waiting for 2 seconds");
}
});
}
},2000);
两秒钟后,这将更新您的第二个textView。 您可以与其他人做几乎相同的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.