Hello Responsible,
I am doing an Android Developement and i have a doubt in datebpicker dialog.
When a button is clicked,a date picker pops up and user should be able to select the date.
Below is the code written
The code is successfully compiled and when i click a button,the dialog pops as shown in image 1.But i want date picker as image 2
Please let me know where do i have to change the code.
Thanks in advance
I am doing an Android Developement and i have a doubt in datebpicker dialog.
When a button is clicked,a date picker pops up and user should be able to select the date.
Below is the code written
Java:
package com.example.jeyshree.datedialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button B1;
int day_x, month_x, year_x;
static final int id=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
B1 = (Button)findViewById(R.id.button);
B1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
showDialog(id);
}
});
}
@Override
protected Dialog onCreateDialog(int id1)
{
if (id1==id)
return new DatePickerDialog(MainActivity.this,listener,year_x,month_x,day_x);
return null;
}
protected DatePickerDialog.OnDateSetListener listener
=new DatePickerDialog.OnDateSetListener()
{
public void onDateSet(DatePicker view,int year,int month,int day)
{
year_x=year;
month_x=month;
day_x=day;
Toast.makeText(MainActivity.this,Integer.toString(day_x)+":"+Integer.toString(month_x)+":"+
Integer.toString(year_x),Toast.LENGTH_SHORT).show();
}
};
}
Please let me know where do i have to change the code.
Thanks in advance