-3
如何刪除錯誤,是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
它顯示什麼錯誤? – Piyush 2014-10-03 05:30:01