これは私のデータベースのスクリーンショットです。データを取得するのに多くの試みがありましたが、常にnullが返されるようです。私はfirebaseデータベースを使用しています。私はこのレイアウトにこのデータをどのように取り込むのか知りたいと思っていました。ところで、私はjavaとandroidに新しいので、質問に答えるときにそれを考慮してください。私が持っていたもう一つの質問は、それがクリックされたときにイメージの意図をどのように通すのかということでした。私は自宅のレイアウトで複数の画像ビューを使用していますが、その処理方法を理解できません。前もって感謝します。Firebaseからレイアウトにデータを取得
//製品データベース mDatabaseRef.child( "製品")から取得画像。addValueEventListener(新しいValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Product product = dataSnapshot.child("Product ID").getValue(Product.class);
product_1_name = dataSnapshot.child("Product 1").child("Product Name").getValue().toString();
product_1_price = dataSnapshot.child("Product 1").child("Product Price").getValue().toString();
product_1_urlimage = dataSnapshot.child("Product 1").child("Product Image").getValue().toString();
product_2_name = dataSnapshot.child("Product 2").child("Product Name").getValue().toString();
product_2_price = dataSnapshot.child("Product 2").child("Product Price").getValue().toString();
product_2_urlimage = dataSnapshot.child("Product 2").child("Product Image").getValue().toString();
product_3_name = dataSnapshot.child("Product 3").child("Product Name").getValue().toString();
product_3_price = dataSnapshot.child("Product 3").child("Product Price").getValue().toString();
product_3_urlimage = dataSnapshot.child("Product 3").child("Product Image").getValue().toString();
product_4_name = dataSnapshot.child("Product 4").child("Product Name").getValue().toString();
product_4_price = dataSnapshot.child("Product 4").child("Product Price").getValue().toString();
product_4_urlimage = dataSnapshot.child("Product 4").child("Product Image").getValue().toString();
product_5_name = dataSnapshot.child("Product 5").child("Product Name").getValue().toString();
product_5_price = dataSnapshot.child("Product 5").child("Product Price").getValue().toString();
product_5_urlimage = dataSnapshot.child("Product 5").child("Product Image").getValue().toString();
product_6_name = dataSnapshot.child("Product 6").child("Product Name").getValue().toString();
product_6_price = dataSnapshot.child("Product 6").child("Product Price").getValue().toString();
product_6_urlimage = dataSnapshot.child("Product 6").child("Product Image").getValue().toString();
product_7_name = dataSnapshot.child("Product 7").child("Product Name").getValue().toString();
product_7_price = dataSnapshot.child("Product 7").child("Product Price").getValue().toString();
product_7_urlimage = dataSnapshot.child("Product 7").child("Product Image").getValue().toString();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
プライベートView.OnClickListener HomeImageClickListener =新しいView.OnClickListener(){ テント意図;
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.iv_hotcakes_topleft:
intent = new Intent(getContext(), ProductDetailActivity.class);
intent.putExtra("title", product_1_name);
intent.putExtra("url", product_1_urlimage);
intent.putExtra("price", product_2_price);
startActivity(intent);
break;
case R.id.iv_hotcakes_bottomleft:
intent = new Intent(getContext(), ProductDetailActivity.class);
intent.putExtra("title", product_2_name);
intent.putExtra("url", product_2_urlimage);
intent.putExtra("price", product_2_price);
startActivity(intent);
break;
case R.id.iv_hotcakes_right:
intent = new Intent(getContext(), ProductDetailActivity.class);
intent.putExtra("title", product_3_name);
intent.putExtra("url", product_3_urlimage);
intent.putExtra("price", product_3_price);
startActivity(intent);
break;
case R.id.iv_specials_left:
intent = new Intent(getContext(), ProductDetailActivity.class);
intent.putExtra("title", product_4_name);
intent.putExtra("url", product_4_urlimage);
intent.putExtra("price", product_4_price);
startActivity(intent);
break;
case R.id.iv_specials_right:
intent = new Intent(getContext(), ProductDetailActivity.class);
intent.putExtra("title", product_5_name);
intent.putExtra("url", product_5_urlimage);
intent.putExtra("price", product_5_price);
startActivity(intent);
break;
case R.id.iv_categories_top_left:
intent = new Intent(getContext(), ProductDetailActivity.class);
intent.putExtra("title", product_6_name);
intent.putExtra("url", product_6_urlimage);
intent.putExtra("price", product_6_price);
startActivity(intent);
break;
case R.id.iv_categories_top_right:
intent = new Intent(getContext(), ProductDetailActivity.class);
intent.putExtra("title", product_7_name);
intent.putExtra("url", product_7_urlimage);
intent.putExtra("price", product_7_price);
startActivity(intent);
break;
case R.id.iv_categories_center_left:
intent = new Intent(getContext(), ProductDetailActivity.class);
intent.putExtra("title", "Muffins");
intent.putExtra("url", url);
intent.putExtra("price", "280");
startActivity(intent);
break;
case R.id.iv_categories_center_right:
intent = new Intent(getContext(), ProductDetailActivity.class);
intent.putExtra("title", "Muffins");
intent.putExtra("url", url);
intent.putExtra("price", "280");
startActivity(intent);
break;
case R.id.iv_categories_bottom_left:
intent = new Intent(getContext(), ProductDetailActivity.class);
intent.putExtra("title", "Muffins");
intent.putExtra("url", url);
intent.putExtra("price", "280");
startActivity(intent);
break;
case R.id.iv_categories_bottom_right:
intent = new Intent(getContext(), ProductDetailActivity.class);
intent.putExtra("title", "Muffins");
intent.putExtra("url", url);
intent.putExtra("price", "280");
startActivity(intent);
break;
}
}
};
これまでに何を試しましたか? –
これは、私がデータベースのデータを取得している方法です。これが私のデータベースです。私がやっていることは、文字列を使ってデータベースからデータを取得することによって、画像ビューを塗りつぶすことです。私はpojoについて多くのチュートリアルを見てきましたが、私がそれを使用するとnullを返します。 https://ibb.co/hpviJk https://ibb.co/et9wM5 https://ibb.co/et9wM5https://ibb.co/mpRnTk。 –
私たちにいくつかのコードを教えてください。 –