gpt4 book ai didi

c# - MvxGridView ItemClick 未触发

转载 作者:行者123 更新时间:2023-11-30 04:55:35 25 4
gpt4 key购买 nike

我正在努力做一些看似微不足道的事情。

我有一个像这样的 MvxGridView

<?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>

这是模板

<?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>

这是 View 模型

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);
}

问题是当我点击一个网格项目时命令没有被触发。其他信息,gridview 显示在一个 fragment 中,而 SubjectFeaureView 也是一个 fragment ,因此它将从一个 fragment 导航到另一个 fragment 。我不认为这应该是一个问题,不过。我错过了什么?我对此很陌生。

最佳答案

删除 android:clickable="true"解决了我的问题。

关于c# - MvxGridView ItemClick 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59256273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com