title: how to use date and time picker in android and what is the error that i have and how to fix it
body: <p>I am a creating a simple android application that use <code>date and time picker</code> but the system give me an syntax error how to fix this error ??</p>
  
  <p>The app allow the user to select a date and time than the it will be displayed in a <code>TextView</code> </p>
  
  <p>the error is :   in the onclick method in the if statement <strong>dialogpick</strong> and <strong>timepick</strong>     the error say : <strong>timepick/dialogpick  cannot be resolved to a variable</strong></p>
  
  <h1>MainActivity.java</h1>
  
  <pre><code>package com.example.datetime;
  
  import java.text.DateFormat;
  import java.util.Calendar;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.app.DatePickerDialog;
  import android.app.DatePickerDialog.OnDateSetListener;
  import android.app.TimePickerDialog;
  import android.view.Menu;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.DatePicker;
  import android.widget.TextView;
  import android.widget.TimePicker;
  
  public class MainActivity extends Activity implements OnClickListener {
      // btn1=time btn2=date
      Button btn1, btn2;
      TextView txtv;
      Calendar cal = Calendar.getInstance();
      DateFormat dt = DateFormat.getDateTimeInstance();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          btn1 = (Button) findViewById(R.id.button1);
          btn2 = (Button) findViewById(R.id.button2);
          txtv = (TextView) findViewById(R.id.textView1);
          btn1.setOnClickListener(this);
          btn2.setOnClickListener(this);
  
          DatePickerDialog.OnDateSetListener dialogpick = new DatePickerDialog.OnDateSetListener() {
  
              @Override
              public void onDateSet(DatePicker view, int year, int monthofyear,
                      int dayofmonth) {
                  // TODO Auto-generated method stub
                  cal.set(Calendar.YEAR, year);
                  cal.set(Calendar.MONTH, monthofyear);
                  cal.set(Calendar.DAY_OF_MONTH, dayofmonth);
                  updateText();
  
              }
  
              private void updateText() {
                  // TODO Auto-generated method stub
  
              }
  
          };
          TimePickerDialog.OnTimeSetListener timepick = new TimePickerDialog.OnTimeSetListener() {
  
              @Override
              public void onTimeSet(TimePicker view, int hourofday, int minute) {
                  // TODO Auto-generated method stub
                  cal.set(Calendar.HOUR_OF_DAY, hourofday);
                  cal.set(Calendar.MINUTE, minute);
                  updateText();
  
              }
  
              private void updateText() {
                  // TODO Auto-generated method stub
  
              }
  
          };
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      @Override
      public void onClick(View v) {
          // TODO Auto-generated method stub
  
          if (v.getId() == R.id.button1) {
  
              new DatePickerDialog(MainActivity.this, dialogpick,
                      cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
                      cal.get(Calendar.MONDAY)).show();
          } else if (v.getId() == R.id.button2) {
              new TimePickerDialog(MainActivity.this, timepick,
                      cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE))
                      .show();
          }
  
      }
  
  }
  </code></pre>