activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<Button
android:id="@+id/chooseDateButton"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Choose Date"
android:textSize="20dp" />
<TextView
android:id="@+id/displatext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<Button
android:id="@+id/chooseDateButton"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Choose Date"
android:textSize="20dp" />
<TextView
android:id="@+id/displatext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
MainActivity.java:
package com.ram.dpdexample;
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
public class MainActivity extends Activity {
Calendar c = Calendar.getInstance();
TextView display;
int cday, cmonth, cyear;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button changeDate = (Button) findViewById(R.id.chooseDateButton);
display = (TextView) findViewById(R.id.displatext);
changeDate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
new DatePickerDialog(MainActivity.this, d,
c.get(Calendar.YEAR), c.get(Calendar.MONTH), c
.get(Calendar.DAY_OF_MONTH)).show();
}
});
}
DatePickerDialog.OnDateSetListener d = new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
cday = dayOfMonth;
cmonth = monthOfYear + 1;
cyear = year;
display.setText("Choosen date is :" + cday + "/" + cmonth + "/"
+ cyear);
}
};
}
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
public class MainActivity extends Activity {
Calendar c = Calendar.getInstance();
TextView display;
int cday, cmonth, cyear;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button changeDate = (Button) findViewById(R.id.chooseDateButton);
display = (TextView) findViewById(R.id.displatext);
changeDate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
new DatePickerDialog(MainActivity.this, d,
c.get(Calendar.YEAR), c.get(Calendar.MONTH), c
.get(Calendar.DAY_OF_MONTH)).show();
}
});
}
DatePickerDialog.OnDateSetListener d = new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
cday = dayOfMonth;
cmonth = monthOfYear + 1;
cyear = year;
display.setText("Choosen date is :" + cday + "/" + cmonth + "/"
+ cyear);
}
};
}
This comment has been removed by the author.
ReplyDeletehttp://solution2tech.blogspot.in/2013/11/date-picker-in-android.html
ReplyDeletehi ! have you made any tutorial regarding reminder application with alarm ?
ReplyDeleteand can you please help me at this?
ReplyDeleteimport android.os.Bundle;
ReplyDeleteimport android.app.Activity;
import android.view.Menu;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.widget.TimePicker;
public class MainActivity extends Activity {
Calendar c=Calendar.getInstance();
TextView display;
int cday,cmonth,cyear;
TextView disptime;
int chour,cmin,csec;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button changeDate=(Button)findViewById(R.id.bselectdate);
display=(TextView) findViewById(R.id.disptext);
Button changeTime=(Button)findViewById(R.id.bselecttime);
changeDate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new DatePickerDialog(MainActivity.this,d,
c.get(Calendar.YEAR),c.get(Calendar.MONTH),
c.get(Calendar.DAY_OF_MONTH)).show();
}
});
changeTime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new DatePickerDialog(MainActivity.this,d,
c.get(Calendar.HOUR),c.get(Calendar.MINUTE),
c.get(Calendar.SECOND)).show();
}
});
}
DatePickerDialog.OnDateSetListener d = new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
cday = dayOfMonth;
cmonth = monthOfYear + 1;
cyear = year;
display.setText("Choosen date is :" + cday + "/" + cmonth + "/"
+ cyear);
}
};
TimePickerDialog.OnTimeSetListener d1 = new OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hour, int minute,
int second) {
chour = hour;
cmin = minute + 1;
csec = second;
display.setText("Choosen time is :" + chour + "/" + cmin + "/"
+ csec);
}
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
}
};
}
This is my Main Activity code when i am adding time in it it shows calendar...
Hi i will check the code..right now i'm very busy...
DeleteThank you dear i am waiting for your response
Delete