I'm struggling to do something which seems trivial.
I have an MvxGridView like so
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Mvx.MvxGridView
android:id="@+id/subjects_gv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:numColumns="2"
android:verticalSpacing="15dp"
android:gravity="center"
app:MvxItemTemplate="@layout/assigned_subject_view"
app:MvxBind="ItemClick ShowSubjectFeatures;ItemsSource Subjects;"/>
</LinearLayout>
and here is the template
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
local:cardUseCompatPadding="true"
local:cardCornerRadius="5dp">
<RelativeLayout
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:orientation="vertical"
android:clickable="true"
android:background="?android:attr/selectableItemBackground">
<ImageView
android:layout_centerInParent="true"
android:id="@+id/iv_subject_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/english" />
<TextView
android:layout_centerInParent="true"
android:layout_alignParentBottom="true"
android:id="@+id/tv_subject_Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:gravity="center"
android:maxLines="2"
android:stretchMode="spacingWidthUniform"
android:textSize="@dimen/very_small_text"
local:MvxBind="Text Name" />
</RelativeLayout>
</android.support.v7.widget.CardView>
And here is the viewmodel
private readonly IMvxNavigationService _navigationService;
private readonly ISubjectsService _subjectsService;
public SubjectsViewModel(IMvxNavigationService navigationService, ISubjectsService subjectsService)
{
_navigationService = navigationService;
_subjectsService = subjectsService;
}
public MvxObservableCollection<SubjectModel> Subjects { get; set; } = new MvxObservableCollection<SubjectModel>();
public MvxCommand<SubjectModel> ShowSubjectFeatures
{
get
{
// Navigate to subject details viewmodel
return new MvxCommand<SubjectModel>(async subject => await NavigateToFeatures(subject));
}
}
public override async Task Initialize()
{
var response = await _subjectsService.GetAssignedSubjects();
Subjects.AddRange(response.Subjects);
}
private async Task NavigateToFeatures(SubjectModel model)
{
await _navigationService.Navigate<SubjectFeatureViewModel, int>(model.Id);
}
The issue is when I click on a grid item the command isn't triggered. Other info, the gridview is displayed in a fragment and the SubjectFeaureView is also a fragment so it will be navigation from a fragment to fragment. I don't think that should be an issue, tho. What am I missing? I'm pretty new to this.
Removing android:clickable="true" fixed my problem.