如何在textview中打印整数值,以及当我在线程中增加睡眠时间时,它在android中无法正常工作。
package com.example.chaljayar;
import java.util.concurrent.Delayed;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity implements Runnable
{
TextView Tv;
int num = 0, i = 0;
String con = "";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Tv = (TextView)findViewById(R.id.Text);
Thread test = new Thread(this);
test.start();
}
@Override
public void run()
{
// TODO Auto-generated method stub
while(i <= 100)
{
try{
con += Integer.toString(i);
Tv.setText(con);
Thread.sleep(1000);
} catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
}
i++;
}
}
}
答案 0 :(得分:0)
单独尝试线程,另一个尝试线程(尝试/捕获):
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
如果您想在textview中显示有关print int值的任何信息请显示此链接: