![](/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.