0

I am able to bind and render images in recyclerview through adapter when binding adapter data from Activity in Xamarin.Android. but when i am binding it through fragment it's not throwing any exception and i try to debug it as well. but nothing worked.

How can i make them render through fragment in xamain.Android.

here is my binding code: Fragment Code :

 using Android.OS;
using Android.Support.V4.App;
using Android.Views;
using Android.Widget;
using Android.Support.V7.Widget;
public class FragmentOne : Fragment
{
    MyAdapter adapter = null;
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflater.Inflate(Resource.Layout.fragment_One, container, false);
        //recycler view settings
            recyclerView = view.FindViewById<RecyclerView>(Resource.Id.recyclerView);
            recyclerView.SetLayoutManager(new LinearLayoutManager(view.Context, LinearLayoutManager.Vertical, false));
        adapter = new MyAdapter(view.Context, SamepleData.persons.ToList());
        adapter.ItemClick += Adapter_ItemClick;
        recyclerView.SetAdapter(adapter);
        return view;
    }
}

here is my adapter code:

    public MyAdapter(Context context, List<TestModel> data)
    {
        this.data = data;
        this.context = context;
        //this.context = Application.Context;
    }
    public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
    {
        var vh = (MyViewHolder)holder;
            vh.UserName.Text = data[position].FullName;                
            Stream stream = context.Assets.Open("Images/funImages/img1.png");                
            Drawable drawable = Drawable.CreateFromStream(stream, null);
            vh.UserImage.SetImageDrawable(drawable);
    }

recycleview axml code:

 <LinearLayout
        android:id="@+id/linlayout_ItemsRecycle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="3dp"
        android:paddingRight="3dp"
        android:orientation="horizontal"
        android:weightSum="100"
        android:background="#F5F8F8">
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="20"
            android:paddingTop="10dp"
            android:paddingBottom="10dp"
            android:gravity="center_horizontal"
            android:layout_marginRight="5dip">
            <refractored.controls.CircleImageView
                android:id="@+id/img_person"
                android:layout_width="70dp"
                android:layout_height="70dp"
                android:layout_gravity="center"
                app:civ_border_width="2dp"
                app:civ_border_color="#000" />
        </LinearLayout>
Ravi Anand
  • 5,106
  • 9
  • 47
  • 77
  • Can you show your codes about `recyclerView`? – Robbit Mar 09 '18 at 02:56
  • I updated my question with my view code. tell me if i need to put something more. – Ravi Anand Mar 09 '18 at 09:22
  • Hi, the code you provided in your question can't reproduce your problem for us. And about your `RecyclerView`, you need `LayoutManager`, but there is no in your `setLayoutManager` method. – Robbit Mar 09 '18 at 09:31
  • sorry, i missed to put them before. now it's there. it's working well when i bind it through Activity. is there any problem if image size is big? – Ravi Anand Mar 09 '18 at 09:54
  • well, now it's working when i resized images in small size. was throwing an exception as out of memory thorough fragment binding. I followed this https://stackoverflow.com/questions/32244851/androidjava-lang-outofmemoryerror-failed-to-allocate-a-23970828-byte-allocatio – Ravi Anand Mar 09 '18 at 11:03

0 Answers0