这是我的问题,我想指定一个特定的时间和日期。但我的问题是如何在我的程序中实现它?我一直关注这篇文章: A method to store date and time in Android using Firebase?
但问题似乎还没有解决。
这是我的程序,这个程序功能是当您借用某个项目时,您必须指定您想借用该项目的时间和日期。它尚未完全开发,因为时间分配和日期是我目前的问题。
public class Borrow extends AppCompatActivity implements DatePickerDialog.OnDateSetListener , TimePickerDialog.OnTimeSetListener{
private FirebaseAuth firebaseAuth;
private DatabaseReference databaseBorrow;
private Button btnBorrow,btnPick;
private TextView tv_result;
private int day,month,year,hour,minute;
private int dayFinal,monthFinal,yearFinal,hourFinal,minuteFinal;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_borrow);
firebaseAuth = FirebaseAuth.getInstance();
if (firebaseAuth.getCurrentUser() == null) {
finish();
startActivity(new Intent(this, Login.class));
}
Intent intent = getIntent();
btnPick = (Button) findViewById(R.id.btnPick);
tv_result = (TextView) findViewById(R.id.tvResult);
String id = intent.getStringExtra(SearchFragment.BOOK_ID);
btnBorrow=(Button)findViewById(R.id.borrowBtn);
databaseBorrow= FirebaseDatabase.getInstance().getReference("Borrow").child(id);
btnPick.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(Borrow.this , Borrow.this , year,month,day);
datePickerDialog.show();
}
});
btnBorrow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Button();
}
});
}
private void Button(){
String ids = databaseBorrow.push().getKey();
String buttonText = btnBorrow.getText().toString();
BorrowBook borrow = new BorrowBook(ids,buttonText);
databaseBorrow.child(ids).setValue(borrow);
Toast.makeText(this,"Borrow Successfully",Toast.LENGTH_SHORT).show();
}
@Override
public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
yearFinal = i;
monthFinal = i1+1;
dayFinal = i2;
Calendar c= Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
TimePickerDialog timePickerDialog =
new TimePickerDialog(Borrow.this, Borrow.this , hour , minute ,
DateFormat.is24HourFormat(this));
timePickerDialog.show();
}
@Override
public void onTimeSet(TimePicker timePicker, int i, int i1) {
hourFinal = i;
minuteFinal = i1;
//this portion of code is just a testing so that I can see what year and
date that i chose
tv_result.setText("year: "+ yearFinal + "\n" +
"month: "+ monthFinal + "\n" +
"day: "+ dayFinal + "\n" +
"hour: "+ hourFinal + "\n" +
"minute: "+ minuteFinal);
}
}
答案 0 :(得分:0)
您需要创建借用对象(借用对象可以包含签出和截止日期时间戳,项目ID,借用者等),然后将从拾取器获得的值分配给字段。然后,以firebase文档描述将对象保存到firebase的方式将对象保存到firebase。