私は適切に動作し、必要な情報を表示するMvxListViewを持っています。私はItemClickコマンドを正しく動作させることさえできます。今私が理解できないのは、ユーザーがクリックしたビューセルを取得する方法です。ユーザーがクリックしたビューセルを展開したいと思います。ここで私が働いているかのいくつかのコード例は以下のとおりです。MvxListViewを使用してクリックしたListViewアイテムを返すにはどうすればよいですか?
のViewModel:
private List<ContactItemEncrypted> _contactsEncryted;
public List<ContactItemEncrypted> ContactsEncrypted
{
get { return _contactsEncryted; }
set { _contactsEncryted = value; RaisePropertyChanged(() => ContactsEncrypted); }
}
private MvxCommand<ContactItemDecrypted> _itemSelectedCommand;
public System.Windows.Input.ICommand ItemSelectedCommand
{
get
{
_itemSelectedCommand = _itemSelectedCommand ?? new MvxCommand<ContactItemDecrypted>(DoSelectItem);
return _itemSelectedCommand;
}
}
private void DoSelectItem(ContactItemDecrypted item)
{
var message = new ContactSelectedMessage(this, item);
_messenger.Publish(message);
}
ビュー:
[Activity(
Label = "Contacts",
Theme = "@style/AppTheme",
ScreenOrientation = ScreenOrientation.Portrait
)]
public class ContactsListView : MvxAppCompatActivity
{
private MvxListView _listView;
private MvxSubscriptionToken _tokenContactSelected;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.ContactsListScreen);
_listView = FindViewById<MvxListView>(Resource.Id.contactListView);
var messenger = Mvx.Resolve<IMvxMessenger>();
_tokenContactSelected = messenger.SubscribeOnMainThread<ContactSelectedMessage>(ContactSelected);
}
private void ContactSelected(ContactSelectedMessage obj)
{
ExpandView(_listView.Adapter.GetPosition(obj.SelectedContact));
}
private void ExpandView(int index)
{
itemLayout.Visibility = ViewStates.Visible;
}
}
レイアウトリストビューで:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Mvx.MvxListView
android:id="@+id/contactListView"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
local:MvxBind="ItemsSource ContactsDecrypted; ItemClick ItemSelectedCommand; ItemLongClick ItemLongClickCommand"
local:MvxItemTemplate="@layout/contactlistviewitemtemplate" />
</FrameLayout>
そして、 ItemTemplateレイアウト:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:id="@+id/textViewName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:textColor="@color/black"
android:layout_margin="14dp"
custom:MvxBind="Text FullName" />
</LinearLayout>
私はまだビューを展開するコードは書き出されていないことに注意してください。私は私が実際に働くことができるようになるまで私はそれを開始したくありません。
ありがとうございます。