在fn create_user(user_data: Json<UserData>, db: DB) -> Status<Json<Value>> {
let conn = db.conn();
let _new_user_result = user_data.into_inner().into_new_user(&conn);
unimplemented!()
}
中,当我向上或向下滚动时,项目会变得混乱。这意味着它会再次回收项目视图。请有人帮助我,我一直在尝试这么多次。提前谢谢。
这是该问题的屏幕截图 当我向上和向下滚动时,文本视图1(图像中标记为红色)出现在错误的位置
图片1:initial list
图片2:after scrolling list
recyclerview
itemview的XML文件是
private class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.ViewHolder> {
private List<PendingFollowupVO> mPendingFollowupVO;
public MyRecyclerViewAdapter(List<PendingFollowupVO> mpendingfollow) {
mPendingFollowupVO = mpendingfollow;
setHasStableIds(true);
}
//A ViewHolder object stores each of the component views inside the tag field of the Layout,
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_pending_follow_up, parent, false);
ViewHolder viewHolder=new ViewHolder(view);
//ViewDataBinding viewDataBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),R.layout.layout_pending_follow_up,parent,false);
return viewHolder;
}
// It will specified the postion of the elements
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
//ViewDataBinding viewDataBinding=holder.getViewDataBinding;
//List<String> newList = new ArrayList<String>(new HashSet<String>(customerIdlist));
final PendingFollowupVO mpendingfollow = mPendingFollowupVO.get(position);
holder.linearLayout.setTag(mPendingFollowupVO.get(position));
holder.bal.setText(null);
holder.invam.setText(null);
holder.customerName.setText(null);
holder.promised.setText(null);
holder.invpfu.setText(null);
if (holder != null) {
setValue(mpendingfollow.getCustomerName(),mpendingfollow.getCustomerId(), holder.linearLayout, holder.customerName);
holder.invpfu.setText(mpendingfollow.getInvoiceNo());
holder.promised.setText(mpendingfollow.getPromisedDate());
holder.due.setText(mpendingfollow.getDueDate());
holder.invam.setText(CashPunditUtils.formatAmount(mpendingfollow.getInvAmount()));
holder.bal.setText(CashPunditUtils.formatAmount(mpendingfollow.getBalAmount()));
}
}
void setValue(String cnam,long mpendingfollow,LinearLayout linearLayout,TextView cn) {
if (customerId!=(mpendingfollow)) {
showViews(linearLayout, cn,cnam);
cn.setText(cnam);
customerId=mpendingfollow;
}
else
hideViews(linearLayout, cn);
}
private void showViews(LinearLayout layout, View seperator,String cnn) {
layout.setVisibility(View.VISIBLE);
seperator.setVisibility(View.VISIBLE);
}
private void hideViews(LinearLayout row, View seperator) {
row.setVisibility(View.GONE); // if there is a empty space change it with View.GONE
seperator.setVisibility(View.GONE);
}
@Override
public int getItemCount() {
return mPendingFollowupVO.size();
}
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public int position;
protected TextView customerName, invpfu, due, promised, invam, bal;
LinearLayout linearLayout;
public ViewHolder(View view) {
super(view);
this.linearLayout = (LinearLayout) itemView.findViewById(R.id.head3);
this.customerName = (TextView) itemView.findViewById(R.id.customernamepfu);
this.invpfu = (TextView) itemView.findViewById(R.id.inv);
this.due = (TextView) itemView.findViewById(R.id.due2);
this.promised = (TextView) itemView.findViewById(R.id.prom);
this.invam = (TextView) itemView.findViewById(R.id.over);
this.bal = (TextView) itemView.findViewById(R.id.bal);
view.setOnClickListener(this);
}
@Override
public void onClick(View v) {
mFragmentActionListener.setFragmentTitle("Communication");
CommunicationFragment fragment = new CommunicationFragment();
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.home_container, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
Toast.makeText(getActivity(),"ooooo",Toast.LENGTH_LONG).show();
}
}
}
Model类是
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="#FFDFDFDF"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="20dp"
android:id="@+id/head3"
android:layout_marginTop="3dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="@{mPendingFollowupVO.customerName}"
android:background="#2F75B5"
android:textColor="#ffff"
android:textSize="14dp"
android:id="@+id/customernamepfu"
android:textAlignment="center"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="2dp"
android:layout_width="match_parent"
android:layout_below="@+id/head3"
android:id="@+id/head4"
android:layout_height="wrap_content">
<TextView
android:layout_width="65dp"
android:layout_height="25dp"
android:paddingTop="5dp"
android:textSize="13dp"
android:text="Invoice#"
android:layout_marginRight="1dp"
android:background="#b1c1da"
android:textColor="#000"
android:textAlignment="center"/>
<TextView
android:layout_width="80dp"
android:layout_height="25dp"
android:paddingTop="5dp"
android:textSize="13dp"
android:layout_marginRight="1dp"
android:text="Due On"
android:background="#b1c1da"
android:textColor="#000"
android:textAlignment="center"/>
<TextView
android:layout_width="85dp"
android:layout_height="25dp"
android:paddingTop="5dp"
android:textSize="13dp"
android:text="Promised"
android:layout_marginRight="1dp"
android:background="#b1c1da"
android:textColor="#000"
android:textAlignment="center"/>
<TextView
android:layout_width="70dp"
android:layout_height="25dp"
android:paddingTop="5dp"
android:textSize="13dp"
android:text="Inv amount"
android:layout_marginRight="1dp"
android:background="#b1c1da"
android:textColor="#000"
android:textAlignment="center"
android:id="@+id/textView" />
<TextView
android:layout_width="75dp"
android:layout_height="25dp"
android:paddingTop="5dp"
android:textSize="13dp"
android:text="Balance "
android:background="#b1c1da"
android:textColor="#000"
android:textAlignment="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/head5"
android:layout_below="@+id/head4"
android:layout_marginBottom="1dp"
android:layout_marginTop="0dp"
>
<TextView
android:layout_width="65dp"
android:layout_height="25dp"
android:text="@{mPendingFollowupVO.invoiceNo}"
android:id="@+id/inv"
android:paddingTop="5dp"
android:textSize="12dp"
android:layout_marginRight="2dp"
android:background="#ffff"
android:textColor="#000"
android:textAlignment="center"/>
<TextView
android:layout_width="80dp"
android:layout_height="25dp"
android:paddingTop="5dp"
android:textSize="12dp"
android:id="@+id/due2"
android:text="@{mPendingFollowupVO.dueDate}"
android:layout_marginRight="1dp"
android:background="#ffff"
android:textColor="#000"
android:textAlignment="center"/>
<TextView
android:layout_width="85dp"
android:layout_height="25dp"
android:paddingTop="5dp"
android:textSize="12dp"
android:id="@+id/prom"
android:layout_marginRight="1dp"
android:text="@{mPendingFollowupVO.promisedDate}"
android:background="#ffff"
android:textColor="#000"
android:textAlignment="center"/>
<TextView
android:layout_width="70dp"
android:layout_height="25dp"
android:paddingTop="5dp"
android:textSize="12dp"
android:text="@{Double.toString(mPendingFollowupVO.invAmount)}"
android:id="@+id/bal"
android:layout_marginRight="1dp"
android:background="#ffff"
android:textColor="#000"
android:textAlignment="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="25dp"
android:paddingTop="5dp"
android:textSize="12dp"
android:id="@+id/over"
android:text="@{Double.toString(mPendingFollowupVO.balAmount)}"
android:background="#ffff"
android:textColor="#000"
android:textAlignment="center"/>
</LinearLayout>
</RelativeLayout>