On my activity class the RecyclerView is successfully retrieving information in TextView from Firebase and displaying it, however Image View is not showing the image as desired using Picasso.
I've already tried using Piccaso.get().load("image").into() but it still doesn't show the image.
The class for the activity also containing the view holder is:
public class BeefSamosa extends AppCompatActivity {
private FirebaseRecyclerAdapter<DataHome, DataHomeViewHolder> firebaseRecyclerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_beef_samosa);
//Back Button
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Beef Samosa");
RecyclerView recyclerView = findViewById(R.id.beef_view);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
Query query = rootRef.child("DataHome");
FirebaseRecyclerOptions<DataHome> firebaseRecyclerOptions = new FirebaseRecyclerOptions.Builder<DataHome>()
.setQuery(query, DataHome.class)
.build();
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<DataHome, DataHomeViewHolder>(firebaseRecyclerOptions) {
@Override
protected void onBindViewHolder(@NonNull DataHomeViewHolder dataHomeViewHolder, int position, @NonNull DataHome dataHome) {
dataHomeViewHolder.setDataHome(dataHome);
}
@Override
public DataHomeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.homedetail, parent, false);
return new DataHomeViewHolder(view);
}
};
recyclerView.setAdapter(firebaseRecyclerAdapter);
}
@Override
protected void onStart() {
super.onStart();
firebaseRecyclerAdapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
if (firebaseRecyclerAdapter!= null) {
firebaseRecyclerAdapter.stopListening();
}
}
@Override
public boolean onOptionsItemSelected (MenuItem item){
int id = item.getItemId();
if(id == android.R.id.home){
//ends the activity
this.finish();
}
return super.onOptionsItemSelected(item);
}
//DataHomeViewHolder class
private class DataHomeViewHolder extends RecyclerView.ViewHolder {
private TextView titletext, description, ingredients, directions;
private ImageView imagetoo;
DataHomeViewHolder(View itemView){
super(itemView);
imagetoo = (ImageView) itemView.findViewById(R.id.imagetoo);
titletext = itemView.findViewById(R.id.titletext);
description = itemView.findViewById(R.id.description);
ingredients = itemView.findViewById(R.id.ingredients);
directions = itemView.findViewById(R.id.directions);
}
void setDataHome(DataHome DataHome) {
Picasso.get().load("image").into(imagetoo);
String titleto = DataHome.getTitle();
titletext.setText(titleto);
String descriptionto = DataHome.getDescription();
description.setText(descriptionto);
String ingredientsto = DataHome.getIngredients();
ingredients.setText(ingredientsto);
String directionsto = DataHome.getDirections();
directions.setText(directionsto);
}
}
}
The xml file is:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
tools:context=".Fragments.Home"
android:orientation="vertical"
android:scrollbars="vertical"
android:fadeScrollbars="false"
android:background="@color/colorAccent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<!-- Image -->
<ImageView
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="0dp"
android:layout_marginRight="100dp"
android:id="@+id/imagetoo"
android:scaleType="centerCrop"
/>
<!-- Title-->
<TextView
android:id="@+id/titletext"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="90dp"
android:layout_marginTop="30dp"
android:layout_marginRight="100dp"
android:textSize="25sp"
android:textStyle="bold"
android:textColor="@color/black"
android:scaleType="fitStart" />
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_marginTop="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="250dp"
android:background="@color/colorPrimaryDark"
/>
<!-- Description -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginLeft="39dp"
android:text="Description:"
android:textColor="@color/black"
android:textSize="25sp"
android:textStyle="italic" />
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="39dp"
android:textColor="@color/black"
android:textSize="21sp"
android:textStyle="normal" />
<View
android:layout_width="wrap_content"
android:layout_height="4dp"
android:layout_marginLeft="150dp"
android:layout_marginRight="150dp"
android:layout_marginTop="35dp"
android:layout_gravity="bottom"
android:background="@color/colorPrimaryDark"
/>
<!-- Ingredients -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginLeft="39dp"
android:text="Ingredients:"
android:textColor="@color/black"
android:textSize="25sp"
android:textStyle="italic" />
<TextView
android:id="@+id/ingredients"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="39dp"
android:textColor="@color/black"
android:textSize="21sp"
android:textStyle="normal" />
<View
android:layout_width="wrap_content"
android:layout_height="4dp"
android:layout_marginLeft="150dp"
android:layout_marginRight="150dp"
android:layout_marginTop="35dp"
android:layout_gravity="bottom"
android:background="@color/colorPrimaryDark"
/>
<!-- Directions -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginLeft="39dp"
android:text="Directions:"
android:textColor="@color/black"
android:textSize="25sp"
android:textStyle="italic" />
<TextView
android:id="@+id/directions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="39dp"
android:textColor="@color/black"
android:textSize="23sp"
android:textStyle="normal" />
</LinearLayout>
</ScrollView>
The other class is:
public class DataHome {
public DataHome() {}
public String title ,image, description, ingredients, directions;
public DataHome(String title, String image, String description, String ingredients, String directions){
this.title = title;
this.image = image;
this.description = description;
this.ingredients = ingredients;
this.directions= directions;
}
public String getTitle() {
return title;
}
public String getImage() {
return image;
}
public String getDescription() {
return description;
}
public String getIngredients() {
return ingredients;
}
public String getDirections() {
return directions;
}
}
.load()
expects url of your image. Change this line
Picasso.get().load("image").into(imagetoo);
to
Picasso.get().load(DataHome.getImage()).into(imagetoo);