android's DatePickerDialog and TimePickerDialog implementation
Tech-Today

android's DatePickerDialog and TimePickerDialog implementation


Layout (calendar.xml)


android:orientation="vertical" android:layout_
android:layout_>
android:layout_ />


Java Class:

package org.ipiel.demo.layout;

import java.text.DateFormat;
import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;

public class ChronoDemo extends Activity {
DateFormat fmtDateAndTime=DateFormat.getDateTimeInstance();
TextView dateAndTimeLabel;
Calendar dateAndTime=Calendar.getInstance();

DatePickerDialog.OnDateSetListener d=new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
dateAndTime.set(Calendar.YEAR, year);
dateAndTime.set(Calendar.MONTH, monthOfYear);
dateAndTime.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel();
}
};

TimePickerDialog.OnTimeSetListener t=new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
dateAndTime.set(Calendar.HOUR, hourOfDay);
dateAndTime.set(Calendar.MINUTE, minute);
updateLabel();
}
};

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.calendar);

Button btn=(Button)findViewById(R.id.dateBtn);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new DatePickerDialog(
ChronoDemo.this,
d,
dateAndTime.get(Calendar.YEAR),
dateAndTime.get(Calendar.MONTH),
dateAndTime.get(Calendar.DAY_OF_MONTH)).show();
}
});

btn=(Button)findViewById(R.id.timeBtn);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new TimePickerDialog(
ChronoDemo.this,
t,
dateAndTime.get(Calendar.HOUR),
dateAndTime.get(Calendar.MINUTE),
true).show();
}
});

dateAndTimeLabel=(TextView)findViewById(R.id.dateAndTime);
updateLabel();
}

private void updateLabel() {
dateAndTimeLabel.setText(fmtDateAndTime.format(dateAndTime.getTime()));
}
}




- Android Studio - Displaying List View Inside Alertdialog
Android Studio - Displaying List View Inside AlertDialog 1.) Follow this code: ================>Note: custom_dialog_layout.xml is the layout that will pop-up >Note: row.xml is the item used for populating rowAlertDialog.Builder builder = new AlertDialog.Builder(new...

- Android Studio - Creating Material Design App Bar
Android Studio - Creating Material Design App Bar 1.) Set-up the color that we'll use for the app bar: ======================================== >Create a new xml inside values and name it color.xml <resources>     <color name="ColorPrimary">#FF5722</color>...

- Create A Custom Json String Deserializer In Java
On normal cases we really have a lot of ways in doing so, we can use jaxb, jackson and more. But in some cases we really need to improvised, for example in the project I'm working right now I have a date string from a .net application in this format:...

- Jquery Datepicker Show Only The Month And Year
I have created a report search form that filter the monthly record of sales. So I don't really care about the specific day but the month. Jquery has a nice DatePicker library, but it can't be customized to remove the month part, so just hide it...

- Android Bundle Sqlite Database On Application. Create Sqlite Database On First Application Invoke.
How to setup a default sqlite database structure with data in an android application. Add this class and initialize it in your main class that extends Activity. import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase;...



Tech-Today








.