android-RecyclerView在错误的位置设置图像

android-RecyclerView在错误的位置设置图像,第1张

概述我有一个回收站视图,有2种适配器,并且有一个默认的Image.问题在于,当用户没有图像时,有时会加载其他用户图像而不是默认图像.(我还会检查用户是否没有图像链接,它会以编程方式重置默认图像...,所以它应该可以工作=>文本等没有问题,只有图像!)这是一个适配器的xml代码(对于另一个适配器几乎相同):<RelativeLayout xmlns:t

我有一个回收站视图,有2种适配器,并且有一个默认的Image.问题在于,当用户没有图像时,有时会加载其他用户图像而不是默认图像.
(我还会检查用户是否没有图像链接,它会以编程方式重置默认图像…,所以它应该可以工作=>文本等没有问题,只有图像!)

这是一个适配器的xml代码(对于另一个适配器几乎相同):

<relativeLayout xmlns:tools="http://schemas.androID.com/tools"androID:ID="@+ID/rella_rc_item_frIEnd"xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:card_vIEw="http://schemas.androID.com/apk/res-auto"androID:layout_wIDth="match_parent"androID:layout_height="wrap_content"androID:layout_marginBottom="5dp"androID:layout_margintop="8dp"card_vIEw:cardBackgroundcolor="@color/colorCardVIEw"card_vIEw:cardCornerRadius="5dp"><androID.support.v7.Widget.CardVIEw    androID:layout_wIDth="match_parent"    androID:layout_height="70dp"    androID:layout_marginBottom="10dp"    androID:layout_marginStart="15dp"    androID:layout_marginEnd="15dp"    card_vIEw:cardBackgroundcolor="@color/grey_200"    card_vIEw:cardCornerRadius="5dp">    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:orIEntation="horizontal"        androID:gravity="center">        <de.hdodenhof.circleimagevIEw.circleimageVIEw            xmlns:app="http://schemas.androID.com/apk/res-auto"            androID:ID="@+ID/icon_avata"            androID:layout_wIDth="0dp"            androID:layout_height="50dp"            androID:layout_margin="10dp"            androID:src="@drawable/default_avata"            androID:layout_weight="1"            app:civ_border_color="@color/colorPrimary"/>        <linearLayout            androID:layout_wIDth="0dp"            androID:layout_height="match_parent"            androID:layout_marginStart="10dp"            androID:layout_weight="5"            androID:orIEntation="vertical">            <linearLayout                androID:layout_wIDth="match_parent"                androID:layout_height="0dp"                androID:layout_gravity=""                androID:layout_weight="1"                androID:orIEntation="horizontal"                androID:paddingtop="5dp">                <relativeLayout                    androID:layout_wIDth="match_parent"                    androID:layout_height="match_parent">                <TextVIEw                    androID:ID="@+ID/txtname"                    androID:layout_wIDth="match_parent"                    androID:layout_height="match_parent"                    androID:gravity="center_vertical"                    androID:layout_toleftOf="@ID/txtTime"                    androID:textAppearance="?androID:attr/textAppearanceMedium" />                <TextVIEw                    androID:ID="@+ID/txtTime"                    androID:layout_wIDth="wrap_content"                    androID:layout_alignParentRight="true"                    androID:layout_height="match_parent"                    androID:gravity="center_vertical|right"                    androID:textAppearance="?androID:attr/textAppearanceSmall" />                </relativeLayout>            </linearLayout>            <linearLayout                androID:layout_wIDth="match_parent"                androID:layout_height="0dp"                androID:layout_gravity=""                androID:layout_weight="1">                <TextVIEw                    androID:ID="@+ID/txtMessage"                    androID:layout_wIDth="match_parent"                    androID:layout_height="match_parent"                    androID:ellipsize="end"                    androID:gravity="center_vertical"                    androID:lines="1"                    androID:paddingBottom="10dp"                    />            </linearLayout>        </linearLayout>    </linearLayout></androID.support.v7.Widget.CardVIEw>
class ListContactAdapter extends RecyclerVIEw.Adapter<RecyclerVIEw.VIEwHolder> {public List<MessageInfo> ListContacts;private Context context;FirebaseAuth mAuth;String currentuserID;SimpleDateFormat DateFormat = new SimpleDateFormat("dd MMMM,yyyy");SimpleDateFormat TimeFormat = new SimpleDateFormat("hh:mm a");SimpleDateFormat YearFormat = new SimpleDateFormat("yyyy");SimpleDateFormat DayFormat = new SimpleDateFormat("MMMM dd,hh:mm a");FusionProject Fobj = new FusionProject();DatabaseReference VuRef;CommunActivit obj = new CommunActivit();public ListContactAdapter(Context context,List<MessageInfo> ListGroup){    this.context = context;    this.ListContacts = ListGroup;    mAuth = FirebaseAuth.getInstance();    currentuserID = mAuth.getUID();    VuRef = FirebaseDatabase.getInstance().getReference().child("Seen");}public ListContactAdapter (){}@OverrIDepublic RecyclerVIEw.VIEwHolder onCreateVIEwHolder(VIEwGroup parent,int vIEwType) {    if (vIEwType == 1) {        VIEw vIEw = LayoutInflater.from(context).inflate(R.layout.rc_item_contact_me,parent,false);        return new ItemForMe(vIEw);    } else if (vIEwType == 2) {        VIEw vIEw = LayoutInflater.from(context).inflate(R.layout.rc_item_frIEnd,false);        return new ItemForMyFrIEnd(vIEw);    }    return null;}@OverrIDepublic voID onBindVIEwHolder(final RecyclerVIEw.VIEwHolder holder,final int position){    String username = ListContacts.get(position).getFrIEndUsername();    String last_message = ListContacts.get(position).getLastMessage();    String time = ListContacts.get(position).getTime() ;    String image = ListContacts.get(position).getFrIEndPicture();    String FrIEndID = ListContacts.get(position).getFrIEndID();    Date Today = new Date(System.currentTimeMillis());    long yourmilliseconds = (Long.parseLong(time));    Date resultdate = new Date(yourmilliseconds);    String test = DateFormat.format(resultdate).toString(); /**DATE**/    String test2 = TimeFormat.format(resultdate).toString(); /**TIME**/    String test3 = YearFormat.format(resultdate);    String test4 = DayFormat.format(resultdate);    if (holder instanceof ItemForMe)    {        ((ItemForMe) holder).username_frIEnd.setText(username);        ((ItemForMe) holder).last_message.setText("Me : " +last_message);        if (DateFormat.format(Today).equals(test))        {            ((ItemForMe) holder).time.setText(test2);        }        else        {            if (YearFormat.format(Today).equals(test3))            {                String cap = test4.substring(0,1).toupperCase() + test4.substring(1);                ((ItemForMe) holder).time.setText(cap);            }            else {                ((ItemForMe) holder).time.setText(test);            }        }        if (!image.equals("")) {            Picasso.get().load(image).into(((ItemForMe) holder).Profil_frIEnd);        }        else            {            ((ItemForMe) holder).Profil_frIEnd.setimageResource(R.drawable.default_avata);        }        VuRef.child(ListContacts.get(position).getIDMessage()).addListenerForSingleValueEvent(new ValueEventListener()        {            @OverrIDe            public voID onDataChange(@NonNull DataSnapshot dataSnapshot)            {                if (dataSnapshot.exists())                {                    if (dataSnapshot.getValue().toString().equals("Vu"))                    {                        ((ItemForMe) holder).imageVIEw_vu.setimageDrawable(holder.itemVIEw.getContext().getResources().getDrawable(R.drawable.icons8_seen));                    }                    else                    {                        ((ItemForMe) holder).imageVIEw_vu.setimageDrawable(holder.itemVIEw.getContext().getResources().getDrawable(R.drawable.icons8_not_vu));                    }                }            }            @OverrIDe            public voID onCancelled(@NonNull DatabaseError databaseError) {            }        });    }    else    {        ((ItemForMyFrIEnd) holder).username_frIEnd.setText(username);        ((ItemForMyFrIEnd) holder).last_message.setText(last_message);        if (DateFormat.format(Today).equals(test))        {            ((ItemForMyFrIEnd) holder).time.setText(test2);        }        else        {            if (YearFormat.format(Today).equals(test3))            {                String cap = test4.substring(0,1).toupperCase() + test4.substring(1);                ((ItemForMyFrIEnd) holder).time.setText(cap);            }            else {                ((ItemForMyFrIEnd) holder).time.setText(test);            }        }        if (!image.equals("")) {            Picasso.get().load(image).into(((ItemForMyFrIEnd) holder).Profil_frIEnd);        }        else        {            ((ItemForMyFrIEnd) holder).Profil_frIEnd.setimageResource(R.drawable.default_avata);        }    }    holder.itemVIEw.setonClickListener(new VIEw.OnClickListener() {        @OverrIDe        public voID onClick(VIEw v) {            Intent groupeIntent = new Intent(v.getContext(),ChatActivity.class);            Fobj.writefile("FrIEndID",ListContacts.get(position).getFrIEndID(),context);            Fobj.writefile("MessageID",ListContacts.get(position).getIDMessage(),context);            Fobj.writefile("FrIEndname",ListContacts.get(position).getFrIEndUsername(),context);            Fobj.writefile("FrIEndPicture",ListContacts.get(position).getFrIEndPicture(),context);            obj.setsIDFRIEND(ListContacts.get(position).getFrIEndID());            obj.setsIDMESSAGE(ListContacts.get(position).getIDMessage());            obj.setsFRIENDname(ListContacts.get(position).getFrIEndUsername());           context.startActivity(groupeIntent);        }    });} @OverrIDepublic int getItemVIEwType(int position) {    String test = ListContacts.get(position).getSenderID();    if (test.equals(currentuserID))    {        return 1;    }    else        {            return 2;    }}@OverrIDepublic int getItemCount() {    return ListContacts.size();}  }

检索数据:

  List_of_frIEnds.add(0,new MessageInfo(ID,newgroup,profilepicture,MessageID,Date,Message,Time,SenderID));            adapter.notifyDataSetChanged();

因此,您可以在此图像上看到,第一条消息未正确加载.该用户没有图片,但获得了另一个用户的图片用户…

如果有人可以帮助,那就太好了!

我已经调试过了,看来它有时在固定器中的移动次数比在Listsize中的移动次数更多.

最佳答案您可以像这样使用GlIDe.

将此添加到app.gradle文件中

implementation "com.github.bumptech.glIDe:glIDe:4.8.0"annotationProcessor "com.github.bumptech.glIDe:compiler:4.8.0"

像这样用滑行代替毕加索

if (!image.trim().isEmpty())    GlIDe.with(context).load(image).into(((ItemForMyFrIEnd) holder).Profil_frIEnd);
总结

以上是内存溢出为你收集整理的android-RecyclerView在错误位置设置图像 全部内容,希望文章能够帮你解决android-RecyclerView在错误的位置设置图像 所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1145011.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存