android - 获取服务中的活动
问题描述
下面的代码有效。但我知道这不是正确的做事方式,我想知道什么是正确的做法。我有一个在 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;
}
解决方案
您可以尝试使用CurrentActivityPlugin来获取正在显示Application
的当前。Activity
推荐阅读
- python - 将 DataFrame 转换为键作为索引的字典,将值作为其他列作为列表
- angular6 - 为什么jspdf不能在移动网络应用程序上运行
- python - 特殊汉字比较
- java - 如何按字母顺序对包含数字和特殊字符的列表进行排序?
- php - laravel 无法打开流:没有这样的文件或目录错误
- c# - 在ajax成功中更新表的每个td值
- python - WebElement 方法未显示
- html - 内联 SVG
与矢量效果结合时在 Firefox 中中断:非缩放笔画 - node.js - 在 Sequelize 中隐藏列名
- android - 将自己的字体添加到 android 项目