方法无法解决

时间:2016-10-19 21:14:31

标签: android

我正在尝试将数据发送到firebase。

我想在方法中调用时间和日期,并且该方法负责将数据发送到fire base。

当我尝试拨打时间和日期时,它会给我这个错误。

getText.toString method cannot resolved

在这一行:

myRef.setValue(ft1.getText().toString()); 

以及.getText的其他用途。

我的代码:

public class Room1 extends AppCompatActivity {
    boolean hasSetTime = false;
    boolean hasSetDate = false;
    boolean hasSetTime1 = false;

    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.room1);


        final Calendar c = Calendar.getInstance();
        final int year = c.get(Calendar.YEAR);
        final int month = c.get(Calendar.MONTH);
        final int day = c.get(Calendar.DAY_OF_MONTH);
        final int hour = c.get(Calendar.HOUR_OF_DAY);
        final int minute1 = c.get(Calendar.MINUTE);
        final Calendar v = Calendar.getInstance();
        final int hour2 = v.get(Calendar.HOUR_OF_DAY);
        final int minute2 = v.get(Calendar.MINUTE);

        final String date;
        final EditText ft1;
        final EditText fd1;
        final EditText e1;

         ft1 = (EditText) findViewById(R.id.ft1);
        fd1 = (EditText) findViewById(R.id.fd1);
         e1 = (EditText) findViewById(R.id.e1);

        fd1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DatePickerDialog datepick = new DatePickerDialog(Room1.this, new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                        fd1.setText(dayOfMonth + "/" + month + "/" + year);

                        SimpleDateFormat dateFormatter;
                        Date d;
                        String entered_dob;


                        d = new Date(year, month, day);
                        dateFormatter = new SimpleDateFormat("MM-dd-yyyy");
                        entered_dob = dateFormatter.format(fd1.getText());
                        hasSetDate = true;
                        sendDataToFireBase();
                    }
                },
                        year, month, day);
                datepick.setTitle("select date");
                datepick.show();

            }
        });

        e1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TimePickerDialog timepickend = new TimePickerDialog(Room1.this, new TimePickerDialog.OnTimeSetListener() {


                    @Override
                    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                        e1.setText(hourOfDay + ":" + minute);
                        hasSetTime = true;
                        sendDataToFireBase();
                    }
                }, hour2, minute2, true
                );
                timepickend.setTitle("select time");
                timepickend.show();

            }
        });

        ft1.setOnClickListener(new View.OnClickListener() {
                                   @Override
                                   public void onClick(View v) {
                                       TimePickerDialog timepick = new TimePickerDialog(Room1.this, new TimePickerDialog.OnTimeSetListener() {


                                           @Override
                                           public void onTimeSet(TimePicker view, int hourOfDay2, int minute2) {
                                               ft1.setText(hourOfDay2 + ":" + minute2);
                                               hasSetTime1=true;
                                               sendDataToFireBase();
                                           }
                                       }, hour, minute1, true
                                       );
                                       timepick.setTitle("select time");
                                       timepick.show();



                                   }
                               }
        );


    }

    public  void sendDataToFireBase() {

        if (hasSetTime == true && hasSetDate==true&&hasSetTime1==true) {
            FirebaseDatabase database = FirebaseDatabase.getInstance();
            DatabaseReference myRef = database.getReference("Date");
            myRef.setValue(ft1.getText().toString());
            DatabaseReference myRef2 = database.getReference("Time");
            myRef2.setValue(e1.getText().toString());
            DatabaseReference myRef3 = database.getReference("Timereserved");
            myRef2.setValue(fd1.getText().toString());
        }
    }
}

1 个答案:

答案 0 :(得分:0)

public void sendDataToFireBase() {
    ft1 // <-----get rid of this
    if