DATE PICKER ANDROID TUTORIAL
First Create main.xlm file....
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".DateActivity" >
<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="Button" />
<TextView
android:id="@+id/d1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/m1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Month"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/y1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Year"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
Second Create TimerActivity.java file....
public class DateActivity extends Activity implements OnClickListener
{
TextView d,m,y;
Button b;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
d=(TextView)findViewById(R.id.d1);
m=(TextView)findViewById(R.id.m1);
y=(TextView)findViewById(R.id.y1);
b=(Button)findViewById(R.id.button1);
b.setOnClickListener(this);
}
public void onClick(View v)
{
int dd,mm,yy;
Calendar c=Calendar.getInstance();
dd=c.get(Calendar.DAY_OF_MONTH);
mm=c.get(Calendar.MONTH);
yy=c.get(Calendar.YEAR);
mm=mm+1;
d.setText(dd+"");
m.setText(mm+"");
y.setText(yy+"");
}
}
After run your project and click button show the date....
Same as Time You Picker Time in Layout click button after show time....
First Create main.xlm file....
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".DateActivity" >
<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="Button" />
<TextView
android:id="@+id/d1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/m1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Month"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/y1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Year"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
Second Create TimerActivity.java file....
public class DateActivity extends Activity implements OnClickListener
{
TextView d,m,y;
Button b;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
d=(TextView)findViewById(R.id.d1);
m=(TextView)findViewById(R.id.m1);
y=(TextView)findViewById(R.id.y1);
b=(Button)findViewById(R.id.button1);
b.setOnClickListener(this);
}
public void onClick(View v)
{
int dd,mm,yy;
Calendar c=Calendar.getInstance();
dd=c.get(Calendar.DAY_OF_MONTH);
mm=c.get(Calendar.MONTH);
yy=c.get(Calendar.YEAR);
mm=mm+1;
d.setText(dd+"");
m.setText(mm+"");
y.setText(yy+"");
}
}
After run your project and click button show the date....
Same as Time You Picker Time in Layout click button after show time....
No comments :
Post a Comment