开发者

Runtime DatePicker in Non Activity class

can we create a runtime Date Picker Dialog fro开发者_Go百科m a non activity class in android?


In order to create any dialog you need to pass the context (you can pass through constructor or through any function arguments )

Then to create a Date Picker Dialog

 Calendar c = Calendar.getInstance();//To initialize with the current date 
            int mYear = c.get(Calendar.YEAR);
            int mMonth = c.get(Calendar.MONTH);
            int mDay = c.get(Calendar.DAY_OF_MONTH);

        DatePickerDialog dialog= new DatePickerDialog(context, mDateSetListener,
                       mYear, mMonth, mDay);
        dialog.show();


yes u can.. create a class which has constructor that takes context/activity as arguement.. and create its object in an Activity by passing Activity instance.. now in that class create DatePicker by using this object.... i mean like context./*what ever it takes to create a date picker

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜