我想为标签式活动创建一个实时计时器。
然而,这是我得到的错误:
错误:(29,38)错误:找不到符号方法runOnUniThread()
这是我的代码:
package com.example.Sci.livetimeanddate;
import android.icu.text.SimpleDateFormat;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class sub_page01 extends Fragment {
private static final String TAG = "Sub_page01";
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_sub_page01,container,false);
Thread t = new Thread() {
public void run() {
try {
while (!isInterrupted()) {
Thread.sleep(1000);
getActivity().runOnUniThread(new Runnable() {
@RequiresApi(api = Build.VERSION_CODES.N)
public void run() {
TextView tdate = (TextView) view.findViewById(R.id.date);
long date = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy\nhh-mm-ss a");
String dateString = sdf.format(date);
tdate.setText(dateString);
}
});
}
} catch (InterruptedException e) {
}
}
};
t.start();
return view;
}
}
我不确定问题是什么。
答案 0 :(得分:0)
runOnUniThread
中有拼写错误。应该有runOnUiThread