ZAJ
ZAJ

Reputation: 835

cannot get back the date selected from DatePicker

I am trying to get back the date selected in the DatePicker which is shown in a dialog. I mean I have a ActionBarSherlock with a menu which when pressed opens a dialog which has a datepicker and a EditItem.Now when I select a date and the amount I want to get those parameters.but I get error.Can somebody please help me. I have copied my code below

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add("Add Detail").setIcon(R.drawable.ic_compose).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.custom);

    Button cancelButton = (Button) dialog.findViewById(R.id.canelButton);
    final DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker1);

    Button OKButton = (Button) dialog.findViewById(R.id.OKbutton);

    OKButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.d("---------------",datePicker.getDayOfMonth()+" ");
        }
    });

    // if button is clicked, close the custom dialog
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    dialog.show();

    return true;
}

Upvotes: 0

Views: 199

Answers (2)

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132982

you will need to use dialog instance of Dialog if DatePicker Widget is placed in custom layout. try it as:

final DatePicker datePicker = (DatePicker)dialogfi.ndViewById(R.id.datePicker1);

Upvotes: 1

Mohit Rakhra
Mohit Rakhra

Reputation: 165

Its not a big task.. You can do it of your own.. I am providing you the link of the Android Developers.. Hope this helps Link 1

Upvotes: 0

Related Questions