以下代码有效。但是我知道这不是正确的做事方法,我想知道什么是正确的做事方法。我有一个键盘服务,该服务在ListView中显示GIF图像。但是ListView需要一个活动来显示它。如何在ListView中获得活动? (我已经尝试过将服务强制转换为活动。收到无效的强制转换异常)
public override View OnCreateInputView()
{
View imageKeyboardView = (View)LayoutInflater.Inflate(Resource.Layout.ImageKeyboard, null);
listView = imageKeyboardView.FindViewById<ListView>(Resource.Id.List); // get reference to the ListView in the layout
Activity act = MainActivity.Instance;
// populate the listview with data
listView.Adapter = new ImageKeyboardAdapter(act, listOfIconUris);
listView.ItemClick += OnListItemClick; // to be defined
return imageKeyboardView;
}