我的问题是与此活动有关。我想获取时间,将其与数据库上的时间进行比较,然后如果订阅还没有过期,请显示一个按钮,如果它已隐藏它。另外,我想显示用户的信誉,并在顶部显示图像和他的名字。我已经尝试了很多东西,但是由于某种原因它一直崩溃。
g.values.tolist()
在oncreate中,我已设置了所有内容。
public void getthedate(){
calendar = Calendar.getInstance();
final SimpleDateFormat mdformat = new SimpleDateFormat("yyyy / MM / dd ");
// strDate = "Current Date : " + mdformat.format(calendar.getTime());
// futurecal = Calendar.getInstance();
// futurecal.add(Calendar.DATE, 30);
// futuredate = mdformat.format(futurecal.getTime());
DatabaseReference subtime = mDatabase.child("users").child(univ).child(uid);
subtime.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
subtimedate = dataSnapshot.child("subdate").getValue().toString();
String username = dataSnapshot.child("Full name").getValue().toString();
String coinstring = dataSnapshot.child("coins").getValue().toString();
coinview.setText(coinstring);
String imglink = dataSnapshot.child("imageuri").getValue().toString();
Glide.with(c).load(imglink).into(userthing);
hellostring.setText("Hey" + username + "!");
Date subdatecal = null;
try {
subdatecal = mdformat.parse(subtimedate);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar newestcal = Calendar.getInstance();
newestcal.setTime(subdatecal);
if (newestcal.after(mdformat.format(calendar.getTime()))){
substat.setText("Active");
substat.setBackgroundColor(Color.GREEN);
//do something if subscription hasnt expired
}else{
gotonotes.setVisibility(View.GONE);
substat.setText("Expired");
substat.setBackgroundColor(Color.RED);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
/*
DatabaseReference subtime = mDatabase.child("users").child(univ).child(uid).child("subdate");
subtime.setValue(futuredate);
set new subscription
*/
/* if (calendar.after(futurecal)){
use this to check if date has passed
}*/
}
谢谢您的建议!
当活动崩溃时,这是我在android studio上的手机上的logcat
substat = (TextView) findViewById(R.id.substat);
hellostring = (TextView) findViewById(R.id.hellostring);
coinview = (TextView) findViewById(R.id.coinview);
userthing = (ImageView) findViewById(R.id.userimagething);
mDatabase = FirebaseDatabase.getInstance().getReference();
friendbtn = (Button) findViewById(R.id.friendsbtn);
uid = FirebaseAuth.getInstance().getCurrentUser().getUid();