Quantcast
Channel: MVVM Light Toolkit
Viewing all articles
Browse latest Browse all 1826

New Post: ObservableAdapter with custom layout

$
0
0
Hi,

I'm using Xamarin and MVVM Light for Android development and I observed a strange behavior when I tried to use the ObservableAdapter together with a custom listview item layout.

I used the layout quite a while before even using the ObservableAdapter and MVVM Light and it worked fine. It is basically a two line layout where both lines are given a textSize in scale pixels which is a modified version of the layout found here:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="6dip" >

    <TextView
        android:id="@+id/secondLine"
        android:layout_width="fill_parent"
        android:layout_height="26dip"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:text="Description"
        android:textSize="12sp" />

    <TextView
        android:id="@+id/firstLine"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/secondLine"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_alignWithParentIfMissing="true"
        android:gravity="center_vertical"
        android:text="Example application"
        android:textSize="16sp" />

</RelativeLayout> 
Before using the ObservableAdapter I implemented a custom adapter and used the following line for layout inflation:
this.context.LayoutInflater.Inflate(Resource.Layout.ListViewInteractionRow, parent, false);
Since the delegate of the ObservableAdapter does not take the parent parameter I followed this article and converted the line to:
this.LayoutInflater.Inflate(Resource.Layout.ListViewInteractionRow, null);
This line is part of the callback passed to the GetAdapter function and is located in the activity showing the list. So when I do this, the layout is not correctly inflated and only one line of text is shown for every list item. However, when I change use the build-in layout Android.Resource.Layout.SimpleListItem2 it works.

I suspect this has something to do with this explanation.

So wouldn't it be good to pass the parameter ViewGroup parent to the delegate aswell, so it can be used to correctly inflate custom layouts in the callback?
I'm pretty new to this whole matter and I don't know what the current development status is or if I'm missing some pattern I could use.

Thanks in advance!

Viewing all articles
Browse latest Browse all 1826

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>