我在我的活動中有兩種方法。我試圖在我看來顯示這兩種方法的結果。我被困在這裏。我很感謝你的幫助。在onCreate中調用方法
我想打電話給他們在onCreate方法,但我有一個空的屏幕:
這裏是我的代碼:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
Firebase.setAndroidContext(this);
if (FirebaseAuth.getInstance().getCurrentUser() == null) {
startActivity(new Intent(MainActivity.this, Login.class));
} else {
if (FirebaseAuth.getInstance().getCurrentUser() != null) {
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
}
}
firebaseAuth = FirebaseAuth.getInstance();
textView = (TextView) findViewById(R.id.textView);
textView2 = (TextView) findViewById(R.id.textView2);
textView4 = (TextView) findViewById(R.id.textView4);
textView5 = (TextView) findViewById(R.id.textView5);
textView3 = (TextView) findViewById(R.id.textView3);
loss = (FloatingActionButton) findViewById(R.id.loss);
profit = (FloatingActionButton) findViewById(R.id.profit);
statement = (FloatingActionButton) findViewById(R.id.statement);
salereport = (FloatingActionButton) findViewById(R.id.salereport);
sale = (FloatingActionButton) findViewById(R.id.sale);
exp = (FloatingActionButton) findViewById(R.id.exp);
total = (FloatingActionButton) findViewById(R.id.total);
loss.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Katakastatement.class));
}
});
profit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
firebaseAuth.signOut();
//closing activity
finish();
startActivity(new Intent(MainActivity.this, Login.class));
}
});
statement.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, KavisuniTotal.class));
}
});
sale.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, KatakaSales.class));
}
});
exp.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Katakaexp.class));
}
});
salereport.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, kavisunistatement.class));
}
});
total.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, LukenyaSales.class));
}
});
}
private boolean Expenditu() {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
DatabaseReference dref = FirebaseDatabase.getInstance().getReference();
String loc = user.getUid();
dref = dref.child(loc + "Expenditure");
dref.addValueEventListener(new com.google.firebase.database.ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
String Name;
String Locatio;
int totalAmount = 0;
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
DogExpenditure dogExpenditure = postSnapshot.getValue(DogExpenditure.class);
totalAmount += dogExpenditure.getAmount();
textView4.setText(Integer.toString(totalAmount));
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
}
Expenditu();
return Expenditu();
}
private boolean sale() {
FirebaseUser user = firebaseAuth.getCurrentUser();
DatabaseReference dref = FirebaseDatabase.getInstance().getReference();
String loc = user.getUid();
dref = dref.child(loc + "Sales");
dref.addValueEventListener(new com.google.firebase.database.ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
String Name;
String Locatio;
int totalAmounte = 0;
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
DogExpenditure dogExpenditure = postSnapshot.getValue(DogExpenditure.class);
totalAmounte += dogExpenditure.getAmount();
textView5.setText(Integer.toString(totalAmounte));
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
sale();
return sale();
}
public void Names() {
DatabaseReference dreff = FirebaseDatabase.getInstance().getReference();
FirebaseUser user = firebaseAuth.getCurrentUser();
String loc = user.getUid();
dreff = dreff.child(loc);
dreff.addValueEventListener(new com.google.firebase.database.ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
String Name;
String Profit;
String Locatio;
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Farm farm = postSnapshot.getValue(Farm.class);
Name = farm.getName();
Locatio = farm.getLocation();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
System.out.println("ess");
}
請讓你的代碼可讀。 – tynn