public class ShowRecipe extends AppCompatActivity {
private String recipeName;
private ArrayList<Recipe> lst=new ArrayList<Recipe>();
ProgressDialog pg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_recipe);
getInfo();
pg = ProgressDialog.show(this, "Loading", "please wait", true);
databasetry();
init();
}
public void init() {
TextView recipeNameTV = (TextView) findViewById(R.id.show_recipe_TV);
recipeNameTV.setText(""+lst.get(0).getRecipeName());
CheckBox cosher = (CheckBox) findViewById(R.id.checkBoxCosher_ShowRecipe);
CheckBox peanutes = (CheckBox) findViewById(R.id.checkBoxPeanues_ShowRecipe);
CheckBox gloten = (CheckBox) findViewById(R.id.checkBoxGluten_ShowRecipe);
Boolean c=lst.get(0).getCosher();
Boolean p=lst.get(0).getPeanut();
Boolean g=lst.get(0).getGluten();
cosher.setChecked(c);
peanutes.setChecked(p);
gloten.setChecked(g);
}
private void getInfo() {
Bundle extras = getIntent().getExtras();
if (extras != null) {
recipeName = extras.getString("recipeName");
}
}
public void databasetry(){
Firebase myFirebaseRef = new Firebase("https://recipe4u-f7470.firebaseio.com/");
myFirebaseRef.child("Recipes").child(""+recipeName).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Recipe currentUser = dataSnapshot.getValue(Recipe.class);
lst.add(currentUser);
Toast.makeText(ShowRecipe.this, "Name:"+currentUser.toString(), Toast.LENGTH_LONG).show();
pg.dismiss();
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Toast.makeText(ShowRecipe.this, "ERROR", Toast.LENGTH_SHORT).show();
}
});
}
}
私はそれが私のリストとして保存し、それは私にエラーを与えて初期化アクションで使用されるすべてのものを与えるdatabasetry()
アクションで乾杯をするとき。 FYIFirebaseオブジェクトのダウンロード - アンドロイドスタジオ
:私はcurrentUser
(作品)にダウンロード(作品)彼の名前でFirebaseからオブジェクトをダウンロードしたいが(LSTとトーストのtoStringに移動)と私はinit()
でそれを使用したい、それが与えられるよりも、私は誤りです。コードについての解決策やヒントを教えてもらえれば解決できません。
おかげで、あなたのすべての男と少女;)
Works! ありがとうございます;) –
問題ないです、喜んで助けてください。 –