Skip to main content

Date picker android





Button toDate = (Button) findViewById(R.id.doc_dateto);
toDate.setOnClickListener(new OnClickListener() {

private int month;
private int year;
private int day;

@Override
public void onClick(View v) {

OnDateSetListener datePickerListener = null;

datePickerListener = new DatePickerDialog.OnDateSetListener() {



public void onDateSet(DatePicker view,
int selectedYear, int selectedMonth,
int selectedDay) {
year = selectedYear;
month = selectedMonth;
day = selectedDay;

Calendar c = Calendar.getInstance();
c.set(year, month, day);
toDate.setText(c.getTime().toGMTString());
}
};


final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePicker = new DatePickerDialog(
SUP101SampleActivity.this, datePickerListener, year,
month, day);
datePicker.show();

}
});

Comments

Popular posts from this blog

ProgressDialog example using handler android

final ProgressDialog dialog = ProgressDialog . show ( this , "Title" , "Message" , true ); final Handler handler = new Handler () { public void handleMessage ( Message msg ) { dialog . dismiss (); } } ; Thread t = new Thread () { public void run () { // write process code here. handler . sendEmptyMessage ( 0 ); } } ; t . start ();

How to set image button click effect ?

I have one simple solution: using that, you can set the default press effect to the button. // Create button and add event Button addImageView = (Button) bottomView.findViewById(R.id. addImage ); addImageView.setOnClickListener( new OnClickListener () { @Override public void onClick(View v) { // click event } }); //Using this code set touch listener addImageView.setOnTouchListener( touchEffect ); //touch listner OnTouchListener touchEffect = new OnTouchListener() {         public boolean onTouch(View v, MotionEvent event) {             switch (event.getAction()) {                 case MotionEvent. ACTION_DOWN : {                     v.getBackground().setColorFilter(0xe0f47521,PorterDuff.Mode. SRC_ATOP );                     v....

Get cursor position of Edittext android or How to insert text at cursor position.

You can get the Cursor position using the getSelectionStart() and getSelectionEnd() methods. If no text is highlighted, both getSelectionStart() and getSelectionEnd() return the position of the cursor.  myEditText . getSelectionStart (); or myEditText . getSelectionEnd (); How to insert text at cursor position. int curPos = editText .getSelectionStart(); String str = editText .getText().toString(); String str1 = (String) str.substring(0, curPos); String str2 = (String) str.substring(curPos); editText .setText(str1+ "<br/>" + list1 [which] +str2);