解决方案 »

  1.   

    AlerDialog dialog;
    Builder  builder=new Alert.Builder(this);
    builder.setView();dailog=builder. 
      

  2.   


    1.布局
                           < LinearLayout
                            android:id ="@+id/collection_overpass_patrolinfo_linearlayout_XCSJ"
                            android:layout_width ="wrap_content"
                            android:layout_height ="wrap_content"
                            tools:ignore ="UseCompoundDrawables" >                        < TextView
                                android:id ="@+id/collection_overpass_patrolinfo_XCSJ"
                                style= "@style/common_style"
                                android:layout_width ="wrap_content"
                                android:layout_height ="wrap_content"
                                android:hint ="@string/collection_patrolinfo_chose_time" >
                            </ TextView>                        < ImageView
                                android:id="@+id/collection__picker_imageView" 
                                android:layout_width ="wrap_content"
                                android:layout_height ="wrap_content"
                                android:src ="@drawable/datepicker"
                                tools:ignore ="ContentDescription" >
                            </ ImageView>
                        </ LinearLayout>
    2.点击linearlayout弹出日期对话框
                 private LinearLayout linearLayout_XCSJ;
                 private TextView textView_XCSJ ;
                 linearLayout_XCSJ = (LinearLayout) findViewById(R.id.collection_overpass_patrolinfo_linearlayout_XCSJ );                         // 设置按钮的点击事件监听器
                  linearLayout_XCSJ .setOnClickListener( new mSJOnClickListener());
    // 获取一个日历对象
                Calendar date = Calendar. getInstance(Locale. CHINA);             // 当点击DatePickerDialog控件的设置按钮时,调用该方法
                DatePickerDialog.OnDateSetListener d_xcsj = new DatePickerDialog.OnDateSetListener() {
                             @Override
                             public void onDateSet(DatePicker view, int year, int monthOfYear,
                                                     int dayOfMonth) {
                                         // 修改日历控件的年,月,日
                                         // 这里的year,monthOfYear,dayOfMonth的值与DatePickerDialog控件设置的最             新值一致
                                         date.set(Calendar. YEAR, year);
                                         date.set(Calendar. MONTH, monthOfYear);
                                         date.set(Calendar. DAY_OF_MONTH , dayOfMonth);
                                         // 将页面TextView的显示更新为最新时间                                     textView_XCSJ.setText(CommonUtils. getDate( date.getTime()));
                            }
                };             private class mSJOnClickListener implements OnClickListener {
                             @Override
                             public void onClick(View v) {
                                        SimpleDateFormat fromat = new SimpleDateFormat( "yyyy-MM-dd" );
                                        Date d = new Date();
                                         date.setTime(d);                                    DatePickerDialog.OnDateSetListener d_sj = null;
                                         if (v == linearLayout_XCSJ)
                                                    d_sj = d_xcsj ;
                                         else
                                                    d_sj = d_fxwtjtsj ;
                                         // 生成一个DatePickerDialog对象,并显示。显示的DatePickerDialog控件可以选择年月日,并设置
                                         new DatePickerDialog(OverPass_PatrolInfoActivity. this, d_sj,
                                                                 date.get(Calendar. YEAR), date.get(Calendar. MONTH),
                                                                 date.get(Calendar. DAY_OF_MONTH )).show();
                            }
                }拿去用。