1
I made a class called Current Date containing this data:
package com.projeto.projetov1.model;
import java.text.SimpleDateFormat;
public class DataHoraAtual {
long date = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
String dateString = sdf.format(date);
}
and in my main class, when the event is created has this code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//aplica data hora atual do sistema no app
txtDataHoraOcorrencia = (EditText)
findViewById(R.id.txtDataHoraOcorrencia);
DataHoraAtual dataHoraAtual = new DataHoraAtual();
txtDataHoraOcorrencia.setText(dataHoraAtual.toString());
}
Doing so the date and time is not displayed, but the following appears:
com.projecto.projetov1.model.Currenttime@4f3b05b
but if I do so, without calling the class the date and time appears:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//aplica data hora atual do sistema no app
txtDataHoraOcorrencia = (EditText) findViewById(R.id.txtDataHoraOcorrencia);
long date = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
String dateString = sdf.format(date);
txtDataHoraOcorrencia.setText(dataHoraAtual.toString());
}
what I’m doing wrong?
Doing the procedure that Valdeir suggested presented the following:
Thanks @Ramaral worked
– Fabio Souza