В моем приложении я установил видимость текста как невидимую, и я использую базу данных Firebase. Итак, если из моего разрешения базы данных firebase установлено значение true, текстовое представление устанавливается на видимое. Это работает, но проблема в том, что в элементах списка представления переработчика это видно после каждого 8-го элемента списка. Пожалуйста, проверьте Скриншот для моей проблемы
с использованием log.d Я проверил мои элементы, имеющие разрешение true, и результат отображается как true, поскольку я указал только одно истинное значение.
Вот ссылка на мой скриншот
https://ibb.co/YDpfgxF
Menuadapter.java - мой текстовый просмотр был "рекомендован"
package com.example.myapplication;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import static androidx.constraintlayout.widget.Constraints.TAG;
public class MenuAdapter extends RecyclerView.Adapter<MenuAdapter.menuViewHolder>{
Context context;
ArrayList<dish> dishes;
public MenuAdapter(Context c , ArrayList<dish> p)
{
context = c;
dishes = p;
}
@NonNull
@Override
public menuViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
Log.d(TAG ,"On Create View Holder: called");
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview, parent, false);
return new MenuAdapter.menuViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull menuViewHolder holder, final int position) {
holder.dishname.setText(dishes.get(position).getDishname());
holder.dishrate.setText(dishes.get(position).getDishrate());
Picasso.get().load(dishes.get(position).getDishImage()).placeholder(R.drawable.ic_launcher_background).into(holder.dishImage);
holder.dishImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, " : " + dishes.get(position).getDishImage() );
Toast.makeText(context,"clicked on" + dishes.get(position).getDishname(), Toast.LENGTH_SHORT).show();
}
});
boolean flag = dishes.get(position).getPermission();
if (flag){
Log.d(TAG," recommended : " + dishes.get(position).getDishname());
holder.recommended.setVisibility(View.VISIBLE);
}
}
@Override
public int getItemCount() {
return dishes.size();
}
class menuViewHolder extends RecyclerView.ViewHolder {
TextView dishname, dishrate, recommended;
ImageView dishImage;
public menuViewHolder(@NonNull View itemView)
{
super(itemView);
dishname = (TextView) itemView.findViewById(R.id.dishname);
dishrate = (TextView) itemView.findViewById(R.id.dishrate);
dishImage = (ImageView) itemView.findViewById(R.id.dishImage);
recommended = (TextView) itemView.findViewById(R.id.recommended);
}
}
}
CardView.xml - идентификатор текстового обзора "рекомендуется"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:weightSum="2"
android:layout_height="wrap_content"
android:layout_margin="1dp">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="1dp"
app:cardCornerRadius="2dp"
app:cardMaxElevation="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:layout_marginStart="10dp"
android:id="@+id/dishname"
android:textColor="@color/dishnamecolor"/>
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="5dp"
android:text="Recommended"
android:layout_marginStart="10dp"
android:background="@color/recommended"
android:id="@+id/recommended"
android:textColor="#ffffff"
android:layout_height="wrap_content"
android:visibility="invisible"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:id="@+id/dishrate"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textColor="@color/dishratecolor"/>
</LinearLayout>
<LinearLayout
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
>
<ImageView
android:id="@+id/dishImage"
android:layout_width="100dp"
android:scaleType="fitXY"
android:layout_marginRight="10dp"
android:layout_gravity="end"
android:layout_marginLeft="20dp"
android:layout_height="100dp" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
I/art: Do partial code cache collection, code=26KB, data=29KB
After code cache collection, code=25KB, data=28KB
Increasing code cache capacity to 128KB
D/Constraints: On Create View Holder: called
D/Constraints: On Create View Holder: called
D/Constraints: On Create View Holder: called
V/FA: Inactivity, disconnecting from the service
I/art: Do partial code cache collection, code=57KB, data=60KB
I/art: After code cache collection, code=57KB, data=60KB
Increasing code cache capacity to 256KB
D/Constraints: recommended : Chili Paneer(Dry)