I have created a tabbed activity and wish that one of the Tabs will display the current time and date. I have already linked the fragments together however having some issues with displaying the time and date.
This is the error:
Error:(34, 61) error: cannot find symbol method findViewById(int)
and also:
Error:(31, 25) error: cannot find symbol method runOnUiThread()
This is the code;
package com.example.user.plannerv2;
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";
// private Button btnTEST;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_sub_page01,container,false);
Thread t = new Thread() {
public void run() {
try {
while (!isInterrupted()) {
Thread.sleep(1000);
runOnUiThread(new Runnable() {
@RequiresApi(api = Build.VERSION_CODES.N)
public void run() {
TextView tdate = (TextView) 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;
}
Any help would be grateful.