如何删除位于t.start();
public class Timer extends Fragment {
TextView tv1;
Thread t1;
Date d1;
int hour,min,sec;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View android = inflater.inflate(R.layout.timer, container, false);
//((TextView)android.findViewById(R.id.textView)).setText("Timer");
return android;
//tv1 = (TextView)findviewById(R.id.textView1);
t1 = new Thread(){
public void run(){
try{
while (!isInterrupted()) {
Thread.sleep(1000);
runOnUiThread(new Runnable() {
@Override
public void run() {
d1 = new Date();
hour = d1.getHours();
min = d1.getMinutes();
sec = d1.getSeconds();
String displaytime = hour+":"+min+":"+sec ;
// tv1.setText(displaytime);
((TextView)android.findViewById(R.id.textView1)).setText(displaytime);
}});//runOnUiThread ends here
}//While ends here
}catch (InterruptedException e) {
}//Catch ends here
}
/ * ECLIPSE在下面显示错误t1.start();
* /
t1.start();
private void runOnUiThread(Runnable runnable) {
// TODO Auto-generated method stub
}
};//Thread Ends here
}//Oncreate
} //Fragment
答案 0 :(得分:0)
您正在return
声明之后制作该帖子。
将return android;
行移至线程结束后。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View android = inflater.inflate(R.layout.timer, container, false);
t1 = new Thread(){
public void run(){
try{
while (!isInterrupted()) {
Thread.sleep(1000);
runOnUiThread(new Runnable() {
@Override
public void run() {
d1 = new Date();
hour = d1.getHours();
min = d1.getMinutes();
sec = d1.getSeconds();
String displaytime = hour+":"+min+":"+sec ;
// tv1.setText(displaytime);
((TextView)android.findViewById(R.id.textView1)).setText(displaytime);
}});//runOnUiThread ends here
}//While ends here
}catch (InterruptedException e) {
}//Catch ends here
}
/* ECLIPSE IS SHOWING ERROR IN BELOW t1.start(); */
t1.start();
private void runOnUiThread(Runnable runnable) {
// TODO Auto-generated method stub
}
};//Thread Ends here
return android;
}//Oncreate
} //Fragment
答案 1 :(得分:-1)
请发布错误eclipse显示。 并声明“返回android;”应该是oncreateview方法的最后一行。