如何从对话框中获取数据

时间:2013-03-20 09:14:13

标签: android

我有像这样的对话类

class Dialog_Open_DataPicker exten dialog {
Dialog_Open_DataPicker(Context c){}
@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    setContentView(R.layout.dialog_date_picker);
    }
}

我将这个对话称为:

Dialog_Open_DataPicker d = new Dialog_Open_DataPicker(Offer.this);
            d.show();

我想从对话框到我的活动的日期,请问怎么样?提前谢谢

1 个答案:

答案 0 :(得分:2)

创建并显示显示日期的对话框。它在Activity类中的给定文本框中设置值。

public static void showDate(Context context,final TextView view)
{
   final Dialog dialog = new Dialog(context);
   dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
   dialog.setContentView(R.layout.date_dialog);
   dialog.setCancelable(true);
   dialog.show();

   dialog.findViewById(R.id.set_time).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            DatePicker datePicker=(DatePicker)dialog.findViewById(R.id.datePicker);
            int year = datePicker.getYear();
            int month = datePicker.getMonth()+1;
            int day = datePicker.getDayOfMonth();

            StaticDateVariables.DATE_FROM_DATE_DIALOG=new StringBuilder()
            .append(month).append("-").append(day).append("-")
            .append(year).toString();

            view.setText(StaticDateVariables.DATE_FROM_DATE_DIALOG);


            dialog.dismiss();
        }
    });
}