android - 从 ListFragment 中的自定义 CursorAdapter 启动操作模式

标签 android android-listfragment android-cursoradapter contextual-action-bar android-actionmode

我正在尝试为上下文操作栏启动操作模式,但我遇到了问题。我正在为一个扩展 ListFragment 的类使用自定义 CursorAdapter,该类包含在一个扩展 ActionBarActivity 的类中。

结构
GameListActivity (ActionBarActivity)
---- 游戏列表 fragment (ListFragment)
---- ---- custom_adapter (CursorAdapter)

我正在尝试在 custom_adapter 中的 onClick 监听器中启动操作模式。目前,我在 ActionBarActivity 中有 ActionMode.Callback:

public static final ActionMode.Callback AnActionMode = new ActionMode.Callback() {
    // standard funcs (onCreateActionMode, etc)
}

我觉得好像这会更适合 ListFragment,但我已经试过了,但运气并不好。

在我的自定义 CursorAdapter 中,我有一个函数:

private void set_action_mode() {
    if (checked_count > 0)
        if (!is_action_mode_showing)
            ((GameListActivity) m_context).startActionMode(GameListActivity.AnActionMode);
}

我得到的错误是:

Error:(142, 47) error: method startActionMode in class Activity cannot be applied to given types;
required: android.view.ActionMode.Callback
found: android.support.v7.view.ActionMode.Callback
reason: actual argument android.support.v7.view.ActionMode.Callback cannot be converted to android.view.ActionMode.Callback by method invocation conversion

两个类导入(我认为)是正确的类:

import android.support.v7.view.ActionMode;

我原来是关注this链接,但他的实现似乎也不适合我。

有没有办法做我正在做的事情?

最佳答案

我认为你应该使用

startSupportActionMode

代替

startActionMode

希望对您有所帮助!

PS:看看你的 sintaxis。 Java 约定所有变量、对象或方法的名称必须以小写字母开头,并且不允许使用下划线。看来您使用的是 C 命名风格。您可以在 oracle tutorials 找到更多信息。 和 here .

关于android - 从 ListFragment 中的自定义 CursorAdapter 启动操作模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22565576/

相关文章:

java - 如何在java中将当前日期和时间添加10个小时

Android 在 FragmentPagerAdapter 中的 Fragment 中设置 TextView 的文本

android - 光标适配器和 sqlite 示例

Android CheckBox - 删除以前的 setOnCheckedChangeListener

android - Android 中的网络超时

android - 单击按钮更改 ListView 项目的背景颜色

android - fragment 已激活 - 尝试 setArguments 时

android - 在 ListFragment 中设置所选项目的颜色?

android - 创建一个游标适配器以显示比游标本身更多的项目

android - 第一次禁用软键盘上的 0 键