I have attached my code below. i want to get dialogue of Date picker on touch event event of Edit text. i am getting no error but also do not getting any Date dialogue.
Please Help me where i am wrong. Thanx in Advance.
String TAG = "AdvancedSearchActivity";
EditText txtArrCity, txtDepCity, txtDate, txtTime;
public String year, month, day;
public static final int DATE_DIALOG_ID = 1;
// OnDateSetListener dateListener;
String DATE;
/*
* (non-Javadoc)
*
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.advance_search);
txtArrCity = (EditText) findViewById(R.id.edittxt_ArrCity);
txtDepCity = (EditText) findViewById(R.id.edittxt_DepCity);
txtDate = (EditText) findViewById(R.id.edittxt_Date);
txtTime = (EditText) findViewById(R.id.edittxt_Time);
Calendar cal = Calendar.getInstance();
year = String.valueOf(cal.get(Calendar.YEAR));
month = String.valueOf(cal.get(Calendar.MONTH));
day = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
Log.i(TAG, "Year" + year);
Log.i(TAG, "month" + (month + 1));
Log.i(TAG, "Day" + day);
updateDate();
txtDate.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
showDialog(DATE_DIALOG_ID);
Log.i(TAG, "Inside On touch");
return false;
}
});
}
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(TabSample.tabcontext,
dateListener, Integer.parseInt(year),
Integer.parseInt(month), Integer.parseInt(day));
}
return null;
}
// the callback received when the user "sets" the date in the dialog
private DatePickerDialog.OnDateSetListener dateListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int years, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
year = String.valueOf(years);
month = String.valueOf(monthOfYear);
day = String.valueOf(dayOfMonth);
updateDate();
}
};
private void updateDate() {
month = String.valueOf((Integer.parseInt(month) + 1));
if ((Integer.parseInt(month)) < 10) {
Log.i(TAG, "@@@@@ month" + month);
month = "0" + month;
Log.i(TAG, "@@@@@ AFTER month" + month + " MONTH S" + month);
}
day = String.valueOf(day);
if ((Integer.parseInt(day)) < 10) {
day = "0" + day;
}
DATE = year + "-" + month + "-" + day;
Log.i(TAG, "DATE : " + DATE);
txtDate.setText(DATE);
}