Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在RecyclerView中插入Base64中的照片_C#_Xml_Xamarin_Android Recyclerview_Adapter - Fatal编程技术网

C# 在RecyclerView中插入Base64中的照片

C# 在RecyclerView中插入Base64中的照片,c#,xml,xamarin,android-recyclerview,adapter,C#,Xml,Xamarin,Android Recyclerview,Adapter,我正在创建一个回收器视图,其中每个单元格都有一张照片,这些照片应该从数据库提供的Base64字符串转换而来。问题是,我不知道如何设置它 我的用户类: class userProfileModel { public int userId { get; set; } public string username { get; set; } public string userPhotobase64 { get; set; } p

我正在创建一个回收器视图,其中每个单元格都有一张照片,这些照片应该从数据库提供的Base64字符串转换而来。问题是,我不知道如何设置它

我的用户类:

class userProfileModel
    {
        public int userId { get; set; }
        public string username { get; set; }
        public string userPhotobase64 { get; set; }
        public Image userPhoto { get; set; }
回收商的我的单元格模板:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="190dp"
    app:cardElevation="2dp"
    android:layout_marginTop="20dp"
    android:layout_height="190dp">


    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Refractored.Controls.CircleImageView
            android:id="@+id/user_photo_in_interested_choice"
            android:layout_marginTop="10dp"
            android:layout_gravity="center_horizontal"
            android:src="@drawable/photoplaceholder"
            app:civ_border_color="#FF0199"
            app:civ_border_width="2dp"
            android:layout_width="80dp"
            android:layout_height="80dp"/>

        <TextView
            android:id="@+id/username_text_in_interested_choice"
            android:layout_marginTop="10dp"
            android:gravity="center"
            android:textStyle="bold"
            android:text="Nazwa użytkownika"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        

        
                <RelativeLayout
                    android:layout_marginTop="10dp"
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">


                    <ImageView
                        android:id="@+id/deny_in_interested_choice"
                        android:layout_alignParentLeft="true"
                        android:layout_marginTop="5dp"
                        android:src="@drawable/accept_user_photo"
                        android:layout_gravity="center_vertical"
                        android:layout_marginLeft="20dp"
                        android:layout_width="40dp"
                        android:layout_height="40dp"/>

                    <ImageView
                        android:id="@+id/accept_in_interested_choice"
                        android:layout_alignParentRight="true"
                        android:layout_marginTop="5dp"
                        android:src="@drawable/deny_user_photo"
                        android:layout_gravity="center_vertical"
                        android:layout_marginRight="20dp"
                        android:layout_width="40dp"
                        android:layout_height="40dp"/>
            
            
        </RelativeLayout>

    </LinearLayout>
</android.support.v7.widget.CardView>

我不知道如何在适配器中引用映像。我怎么能这么做

适配器:

namespace DatingAppLicencjat.Adapters
{
    class InterestedUsersAdapter : RecyclerView.Adapter
    {
        public event EventHandler<InterestedUsersAdapterClickEventArgs> ItemClick;
        public event EventHandler<InterestedUsersAdapterClickEventArgs> ItemLongClick;
        List<userProfileModel> userList;

        public InterestedUsersAdapter(List<userProfileModel> data)
        {
            userList = data;
        }

        // Create new views (invoked by the layout manager)
        public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
        {

            //Setup your layout here
            View itemView = null;


            itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.user_interested_selection_template, parent, false);

            var vh = new InterestedUsersAdapterViewHolder(itemView, OnClick, OnLongClick);
            return vh;
        }

        // Replace the contents of a view (invoked by the layout manager)
        public override void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position)
        {
            var user = userList[position];

            // Replace the contents of the view with that element
            var holder = viewHolder as InterestedUsersAdapterViewHolder;
            holder.username_in_interested_choice.Text = user.username;
            
            //holder.TextView.Text = items[position];
        }

        public override int ItemCount => userList.Count;

        void OnClick(InterestedUsersAdapterClickEventArgs args) => ItemClick?.Invoke(this, args);
        void OnLongClick(InterestedUsersAdapterClickEventArgs args) => ItemLongClick?.Invoke(this, args);

    }

    public class InterestedUsersAdapterViewHolder : RecyclerView.ViewHolder
    {
        public TextView username_in_interested_choice;
        public CircleImageView user_photo_in_interested_choice;
        public ImageView accept_user_in_interested_choice;
        public ImageView deny_user_in_interested_choice;


        public InterestedUsersAdapterViewHolder(View itemView, Action<InterestedUsersAdapterClickEventArgs> clickListener,
                            Action<InterestedUsersAdapterClickEventArgs> longClickListener) : base(itemView)
        {
            username_in_interested_choice = (TextView)itemView.FindViewById(Resource.Id.username_text_in_interested_choice);
            user_photo_in_interested_choice = (CircleImageView)itemView.FindViewById(Resource.Id.user_photo_in_interested_choice);
            accept_user_in_interested_choice = (ImageView)itemView.FindViewById(Resource.Id.accept_in_interested_choice);
            deny_user_in_interested_choice = (ImageView)itemView.FindViewById(Resource.Id.deny_in_interested_choice);
            itemView.Click += (sender, e) => clickListener(new InterestedUsersAdapterClickEventArgs { View = itemView, Position = AdapterPosition });
            itemView.LongClick += (sender, e) => longClickListener(new InterestedUsersAdapterClickEventArgs { View = itemView, Position = AdapterPosition });
        }
    }

    public class InterestedUsersAdapterClickEventArgs : EventArgs
    {
        public View View { get; set; }
        public int Position { get; set; }
    }
}
namespace datingapplicationcjat.Adapters
{
类InterestedUsersAdapter:RecyclerView.Adapter
{
公共事件事件处理程序项单击;
公共事件事件处理程序项LongClick;
列表用户列表;
公共利益用户适配器(列表数据)
{
用户列表=数据;
}
//创建新视图(由布局管理器调用)
public override RecyclerView.ViewHolder OnCreateViewHolder(视图组父级,int-viewType)
{
//在此处设置布局
View itemView=null;
itemView=LayoutFlater.From(parent.Context).充气(Resource.Layout.user\u interest\u selection\u template,parent,false);
var vh=新的感兴趣用户SaDapterViewHolder(项目视图、OnClick、OnLongClick);
返回vh;
}
//替换视图的内容(由布局管理器调用)
公共覆盖无效OnBindViewHolder(RecyclerView.ViewHolder ViewHolder,int位置)
{
var user=userList[position];
//用该元素替换视图的内容
var holder=viewHolder作为感兴趣的用户SADAPTERVIEWHOLDER;
holder.username\u in\u interest\u choice.Text=user.username;
//holder.TextView.Text=项目[位置];
}
public override int ItemCount=>userList.Count;
void OnClick(InterestedUsersAdapterClickEventArgs args)=>ItemClick?.Invoke(this,args);
void OnLongClick(InterestedUsersAdapterClickEventArgs args)=>ItemLongClick?.Invoke(this,args);
}
公共类InterestedUsersAdapterViewHolder:RecyclerView.ViewHolder
{
公共文本视图用户名在感兴趣的选项中;
公众圈图片查看用户的照片在感兴趣的选择;
公共图像视图接受感兴趣的用户选择;
公共图像视图拒绝用户选择;
公共利益用户AdapterViewHolder(查看项目视图、操作单击侦听器、,
操作(longClickListener):基本(itemView)
{
感兴趣的选项中的username\u=(TextView)itemView.FindViewById(Resource.Id.username\u text\u在感兴趣的选项中);
感兴趣的选项中的用户照片=(CircleImageView)itemView.FindViewById(Resource.Id.user\u photo\u in\u Interest\u choice);
接受感兴趣的选项中的用户=(ImageView)itemView.FindViewById(Resource.Id.accept\u in\u Interest\u choice);
拒绝感兴趣的选项中的用户=(ImageView)itemView.FindViewById(Resource.Id.deny\u in\u Interest\u choice);
itemView.Click+=(发件人,e)=>clickListener(新感兴趣的用户AdapterClickEventArgs{View=itemView,Position=AdapterPosition});
itemView.LongClick+=(发件人,e)=>longClickListener(新感兴趣的用户AdapterClickEventArgs{View=itemView,Position=AdapterPosition});
}
}
公共类感兴趣的用户AdapterClickEventArgs:EventArgs
{
公共视图{get;set;}
公共int位置{get;set;}
}
}

您可以在Get/Set中执行此操作。我刚刚完成了从/到Base64字符串的第一步。您需要实际转换为图像

    class userProfileModel
    {
        public int userId { get; set; }
        public string username { get; set; }
        public string userPhotobase64 { get; set; }
        private Image _userPhoto { get; set; }
        public string userPhoto
        {
            get { return Convert.ToBase64String(_userPhoto); }
            set { userPhoto = Convert.FromBase64String(value); }
        }
    }