Wednesday, June 13, 2012

DatePicker Example

This is a Example of DatePicker

<DatePicker android:id="@+id/datePicker1" android:layout_width="wrap_content" android:layout_height="wrap_content">
</DatePicker>  


public class datetime extends Activity{
private TextView tv;
private DatePicker dp;
private int y,m,day;
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.datetime);
        showDateTime();
}
public void showDateTime()
{
tv=(TextView)findViewById(R.id.txtViewdt);
dp=(DatePicker)findViewById(R.id.datePicker1);
final Calendar c=Calendar.getInstance();
y=c.get(Calendar.YEAR);
m=c.get(Calendar.MONTH);
day=c.get(Calendar.DAY_OF_MONTH);
tv.setText(new StringBuilder().append(m).append("-").append(day).append("-").append(y));
dp.init(y, m, day, null);
}
}

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete