我正在使用包含2个参数的真正基础数据库。我正在使用recyclerview来显示活动中的数据。这是问题所在。在一定数量的行(在本例中为11)之后,它仅复制标头,并且一切正常。我只是想摆脱重复,我需要您的帮助。我会尝试添加一些图片,向您展示发生了什么
这是重复项
这是回收站视图的代码
public class RecyclerAdapter_ZOZNAM extends RecyclerView.Adapter<RecyclerAdapter_ZOZNAM.RecyclerViewHolder_ZOZNAM> {
ArrayList<ZOZNAM_ZAMESTNANCOV> arrayList = new ArrayList<>();
RecyclerAdapter_ZOZNAM(ArrayList<ZOZNAM_ZAMESTNANCOV> arrayList)
{
this.arrayList = arrayList;
}
@Override
public RecyclerViewHolder_ZOZNAM onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_layout_workers,parent,false);
RecyclerViewHolder_ZOZNAM recyclerViewHolder = new RecyclerViewHolder_ZOZNAM(view);
return recyclerViewHolder;
}
@Override
public void onBindViewHolder(RecyclerAdapter_ZOZNAM.RecyclerViewHolder_ZOZNAM holder, int position) {
ZOZNAM_ZAMESTNANCOV zamestnanci = arrayList.get(position);
if (position == 0){
holder.headerTopLine.setVisibility(View.VISIBLE);
holder.header.setVisibility(View.VISIBLE);
holder.headerBottomLine.setVisibility(View.VISIBLE);
}
holder.Name.setText(zamestnanci.getMeno());
holder.Number.setText(zamestnanci.getCislo());
}
@Override
public int getItemCount() {
return arrayList.size();
}
public static class RecyclerViewHolder_ZOZNAM extends RecyclerView.ViewHolder
{
TextView Name,Number;
LinearLayout header;
ImageView headerTopLine, headerBottomLine;
RecyclerViewHolder_ZOZNAM(View view)
{
super(view);
headerTopLine = (ImageView) view.findViewById(R.id.headerTopLine);
header = (LinearLayout) view.findViewById(R.id.header);
headerBottomLine = (ImageView) view.findViewById(R.id.headerBottomLine);
Name = (TextView)view.findViewById(R.id.workName);
Number = (TextView)view.findViewById(R.id.workNumber);
}
}
}
和XML文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="@+id/headerTopLine"
android:visibility="gone"
tools:visibility="visible"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000"/>
<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="CELÉ MENO"
android:gravity="center_horizontal"
android:textSize="20dp"
android:textStyle="bold"
/>
<ImageView
android:paddingTop="10dp"
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#000"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="TELEFÓN"
android:gravity="center_horizontal"
android:textSize="20dp"
android:textStyle="bold"
/>
<ImageView
android:paddingTop="10dp"
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#000"/>
</LinearLayout>
<ImageView
android:id="@+id/headerBottomLine"
android:visibility="gone"
tools:visibility="visible"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Celé meno"
android:gravity="center_horizontal"
android:textSize="15dp"
android:id="@+id/workName"
android:textStyle="bold"
/>
<ImageView
android:paddingTop="10dp"
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#000"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text=""
android:gravity="center_horizontal"
android:textSize="15dp"
android:id="@+id/workNumber"
android:textStyle="bold"
/>
<ImageView
android:paddingTop="10dp"
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#000"/>
</LinearLayout>
<ImageView
android:paddingTop="10dp"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#000"
android:id="@+id/footer"/>
</LinearLayout>
这就是我在活动中使用它的方式
recyclerView = (RecyclerView) findViewById(R.id.dbViewworkers);
arrayList.clear();
layoutManager = new LinearLayoutManager(workersActivity.this);
recyclerView.setLayoutManager(new GridLayoutManager(workersActivity.this, 1, GridLayoutManager.VERTICAL, false));
recyclerView.setHasFixedSize(true);
cursor.moveToFirst();
do {
ZOZNAM_ZAMESTNANCOV zamestnanci = new ZOZNAM_ZAMESTNANCOV(cursor.getString(1), cursor.getString(2));
arrayList.add(zamestnanci);
} while (cursor.moveToNext());
workDb.close();
adapter = new RecyclerAdapter_ZOZNAM(arrayList);
recyclerView.setAdapter(adapter);
答案 0 :(得分:0)
在适配器中使用此功能。
@Override
public int getItemViewType(int position) {
return position
}