0
votes

I am Creating MvvmCross PCL using Visual Studio 2013 and targeting frameworks are

  • WP8 and higher
  • .Net Framwork 4.5 and higher
  • Silverlight 5
  • Xamarin Android
  • Xamarin iOS

In one of my MvxViewModel,I have one public property of List in data from some service is get stored.In android , I have populated a MvxListView with this List .

Now upon clicking one of the listitem I want to call new viewModel which also populate another List.And corresponding MvxListView will have a ItemTemplate as follows

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           xmlns:local="http://schemas.android.com/apk/res/KittensView.Droid"
           android:orientation="horizontal"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent">
     <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        local:MvxBind="Text Name" />
     <RatingBar
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        local:MvxBind="Text Rating" />
     <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Next" />
</LinearLayout>

In this axml layout,I want to show one listItem at a time and upon clicking on above button,a next listItem Should replace existing listItem until all the data in a corresponding List is gets displayed on UI.

How can I achieve this?PLEASE help me...... Thanks in advance for any helpful suggestions.

1

1 Answers

0
votes

You can create properties for: a list of your objects (DataItem), an instance of your object and index

private int _index = 0;
private List<DataItem> _dataitems;
private DataItem _dataItem;
public DataItem DataItem { 
    get { return _dataItem; } 
    set 
    { 
        DataItem = value; 
        RaiseOnProperty(()=>DataItem); 
    }

public IMvxCommand ShowNextItemCommand
{
    get 
    { 
        return new MvxCommand(()=> {
            _index++;
            DataItem = _dataitems.ElementAt[_index]
        });
    }
}

In your AXML, you can do this :

<?xml ... />
<LinearLayout ...
 <TextView ...
    local:MvxBind="Text Name1" />
 <TextView ...
    local:MvxBind="Text Name2" />
 <Button ...
    android:text="Next"
    local:MvxBind="Click ShowNextItemCommand" />
</LinearLayout>

I think it works.