gpt4 book ai didi

android - 如何使用 SherlockListFragment 的上下文操作模式

转载 作者:搜寻专家 更新时间:2023-11-01 08:05:59 26 4
gpt4 key购买 nike

我想在我的应用程序中使用上下文操作栏 (CAB),但它与旧版本的 Android 不兼容,所以我正在使用本教程:http://www.miximum.fr/tutos/849-porting-the-contextual-anction-mode-for-pre-honeycomb-android-apps我的代码是:

public class SongsFragment extends SherlockListFragment implements
LoaderManager.LoaderCallbacks<Cursor>, OnLongClickListener{

...
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
activity = this.getActivity();
...
mMode = null;
mListView = getListView();
mListView.setItemsCanFocus(false);
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
mListView.setOnLongClickListener(this);

}

@Override
public boolean onLongClick(View v) {
SparseBooleanArray checked = mListView.getCheckedItemPositions();
boolean hasCheckedElement = false;
for (int i = 0; i < checked.size() && !hasCheckedElement; i++) {
hasCheckedElement = checked.valueAt(i);
}

if (hasCheckedElement) {
if (mMode == null) {
mMode = activity.startActionMode(mActionModeCallback);
}
} else {
if (mMode != null) {
mMode.finish();
}
}
return false;
}

private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// Create the menu from the xml file
activity.getSupportMenuInflater().inflate(R.menu.cab_songs, menu);
return true;
}
...

我有错误:

  1. -"activity.startActionMode(mActionModeCallback);": Activity 类型中的方法 startActionMode(ActionMode.Callback) 不是适用于参数(ActionMode.Callback)
  2. -activity.getSupportMenuInflater().inflate(R.menu.cab_songs, menu);": 方法 getSupportMenuInflater() 未定义输入 FragmentActivity

有什么想法吗?是否有使用 sherlock 的 CAB 的另一种解决方案?

最佳答案

ActionModeMenuInflater 的导入更改为它们的 ActionBarSherlock 等效项(com.actionbarsherlock.view.ActionModecom.actionbarsherlock .view.MenuInflater).

关于android - 如何使用 SherlockListFragment 的上下文操作模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14296963/

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