LayoutInflater里面的日期对话框 - android

时间:2017-01-13 05:21:10

标签: java android date layout

我正在尝试在EditText上设置DatePickerDialog Click在LayoutInflater中的Click。用户点击它时必须填写日期。找到了一对教程,但没有那样!任何人都可以帮助我或指出我正确的方向吗?

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                LayoutInflater li = LayoutInflater.from(Places_mainActivity.this);
                View getEmpIdView = li.inflate(R.layout.places_dialog_insert, null);



                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Places_mainActivity.this);
                // set places_main_insert.xml to alertdialog builder
                alertDialogBuilder.setView(getEmpIdView);

                final EditText nameInput = (EditText) getEmpIdView.findViewById(R.id.NameeditText);
                final EditText LocationInput = (EditText) getEmpIdView.findViewById(R.id.Location_textView);
                final EditText DescInput = (EditText) getEmpIdView.findViewById(R.id.desc_textView);
                final EditText LatitudeInput = (EditText) getEmpIdView.findViewById(R.id.LatitudetextView6);
                final EditText LongitudeInput = (EditText) getEmpIdView.findViewById(R.id.LongitudetextView);
                final EditText PriceInput = (EditText) getEmpIdView.findViewById(R.id.PriceEditText);
                final RatingBar RankingInput = (RatingBar)getEmpIdView.findViewById(R.id.ratingBarInsert);
                final EditText NotesInput = (EditText) getEmpIdView.findViewById(R.id.NoteseditText);
               // final EditText VisitDate = (EditText)getEmpIdView.findViewById(R.id.dateVisit);

                // set dialog message
                alertDialogBuilder
                        .setTitle("New Place")
                        .setCancelable(true)
                        .setPositiveButton("Add", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int id) {
                                // get user input and set it to result
                                // edit text
                                Toast.makeText(getApplicationContext(),"",Toast.LENGTH_SHORT).show();

                                int year_x,month_x,day_x;


                                String name = nameInput.getText().toString();
                                String location = LocationInput.getText().toString();
                                String desc = DescInput.getText().toString();
                                String latitude = LatitudeInput.getText().toString();
                                String longitude = LongitudeInput.getText().toString();
                                String price = PriceInput.getText().toString();
                                Double rank = Double.parseDouble(String.valueOf(RankingInput.getRating()).toString());
                                Integer r = Integer.parseInt(String.valueOf(rank).replace(".0",""));
                                String notes = NotesInput.getText().toString();


                                Boolean isNameValid = isNameValid(name);
                                Boolean isLocationValid = isLocationValid(location);
                                Boolean isDescValid = isDescValid(desc);
                                if (isNameValid || isLocationValid) {
                                    insertPlace(name,location,desc,latitude,longitude,price,r,notes);
                                    restartLoader();
                                }
                                 if (isNameValid || isLocationValid || isDescValid) {
                                        Toast.makeText(getApplicationContext(), "Please check Name and Location. They cannot be null", Toast.LENGTH_SHORT).show();
                                    }
                            }
                        }).create().show();
            }
        });

0 个答案:

没有答案