Package Name : selva.datepicker
Project Name : DatePicker
Version : 1.5 (Supports 1.5 and above versions)
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<DatePicker
android:id="@+id/datePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Date" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<DatePicker
android:id="@+id/datePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Date" />
</LinearLayout>
DatePickerActivity.java
package selva.datepicker;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Toast;
public class DatePickerActivity extends Activity {
DatePicker datePicker;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
datePicker = (DatePicker) findViewById(R.id.datePicker1);
Button btnOpen = (Button) findViewById(R.id.button1);
btnOpen.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(getBaseContext(),"Date selected:" + datePicker.getMonth() +
"/" + datePicker.getDayOfMonth() +
"/" + datePicker.getYear() ,Toast.LENGTH_SHORT).show();
}
});
}
}
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Toast;
public class DatePickerActivity extends Activity {
DatePicker datePicker;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
datePicker = (DatePicker) findViewById(R.id.datePicker1);
Button btnOpen = (Button) findViewById(R.id.button1);
btnOpen.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(getBaseContext(),"Date selected:" + datePicker.getMonth() +
"/" + datePicker.getDayOfMonth() +
"/" + datePicker.getYear() ,Toast.LENGTH_SHORT).show();
}
});
}
}
OUTPUT:
click GetDate Button
No comments:
Post a Comment