I would like to display current Date and time in a Textview in my app fragments, in the Format : DD/MM/YEAR:H:Min but I have no idea how to code this up as I am new to programming. Where/What to begin with?
my current code :
package com.example.myshops;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.Fragment;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class Monday_fragment extends Fragment implements OnClickListener { private TextView datetimetext;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.item1_fragment, container, false);
Button nextpageButton = (Button) v.findViewById(R.id.Item2Button);
nextpageButton.setOnClickListener((OnClickListener) getActivity());
return v;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.nextpageButton:
break;
}
datetimetext.setText("" + DateFormat.format("dd/MM/yyyy kk:mm", System.currentTimeMillis()));
//---Inflate the layout for this fragment---
//return inflater.inflate( R.layout.item1_fragment, container, false);
}
}