- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我通过扩展 BaseExpandableListAdapter 来填充展开的 ListView 。
ChildView 的代码:
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
LayoutInflater in=getLayoutInflater();
convertView=in.inflate(R.layout.details, null);
//set text for various TextViews from ArrayList1
return convertView;
}
GroupView 代码:
public View getGroupView(final int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
LayoutInflater li= getLayoutInflater();
convertView=li.inflate(R.layout.list, null);
//add data to ArrayList1 and set text for various TextViews
return convertView;
}
如果一个组被展开并且我长按任何后续组 onItemLongClick 方法获取参数 itemIndex 的(实际索引 + 1)值。因此,我得到 arrayindexoutofbounds 异常。
elview.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
final int itemIndex, long arg3) {
Log.e("index selected", itemIndex+"");
return false;
}});
我是不是漏掉了什么?
最佳答案
我没有看到您为上下文菜单注册适配器...
以下是我如何顺利完成的部分内容:
适配器创建
mAdapter = new MyExpandableListAdapter(mGroupsCursor, getActivity(),
R.layout.explistlayout,
R.layout.explistlayout1,
new String[] { "_id" },
new int[] { android.R.id.text1 },
new String[] { child },
new int[] { android.R.id.text1 });
lv.setAdapter(mAdapter);
registerForContextMenu(lv);
上下文菜单和操作
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
int type = ExpandableListView.getPackedPositionType(info.packedPosition);
if (type == 1) {
menu.setHeaderTitle("Event Operations");
menu.add(0, v.getId(), 0, "Edit Event");
menu.add(0, v.getId(), 0, "Delete Event");
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
if (item.getTitle() == "Edit Event") {
mRowId = info.id;
EventAddFragment eventadd = new EventAddFragment();
getFragmentManager().beginTransaction()
.replace(R.id.rightpane, eventadd).commit();
} else if (item.getTitle() == "Delete Event") {
mDbHelper.deleteEvent(info.id);
mGroupsCursor.requery();
return true;
}
return super.onContextItemSelected(item);
}
您还可以查看 this SO question了解更多详情。
希望这对您有所帮助。
关于android - 如果前面的组被展开,则 Expanded ListView 的 setOnItemLongClickListener 给出不正确的 itemIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10369281/
我遇到了这个问题,我无法收到此事件,某些东西阻止了我在 listView 中的一个项目,但我不知道是什么,我检查了对设置为 false 的项目的关注,但它没有用。还要检查将项目设置为 onlongcl
我试图让 Spinner 在用户长时间点击某个项目时表现不同。我有一些项目的微调器,我想要两件事。 当用户简单点击一个项目时,我想正常选择它。 当用户长时间点击某个项目时,我想显示对话框,其中包含“编
我在 Android ListView 中有一个消息列表。我想在长按时从列表中删除消息。我已经在列表选择器中声明了所有状态,但仍处于长按状态。长按后,列表中的特定项目不会保持焦点或选中状态。我尝试设置
这是我的代码: clientGridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
我的问题是这样的:当我长按项目时,会出现两个 View 。 请参阅下面我的 java 类代码。请帮忙。 mListView.setOnItemClickListener(new AdapterView
在下面的代码中,onItemLongClick 仅在我注释掉 onTouchListener 时才起作用。我需要能够注册滑动以及长按。我做错了什么? public class MainPageActi
我创建了一个功能,当用户简单地点击该项目时,在点击项目的屏幕上显示 Toast,一个警告: 我的 .ts 文件中的函数: itemSelected(item: string) { this.t
我正在尝试将 OnItemLongClickListener 用于 Android 上的 listView。此代码在添加到 onCreate 方法时工作正常。 mContactList.setOnIt
在 ListView 中,我同时使用了 setOnItemClickListener() 和 setOnItemLongClickListener()。当我点击一个项目时它工作正常但是当我长按一个项目
我希望有人能帮我解决这个问题。我有一个 ListView ,我希望列表的每一行都可以点击并且可以长时间点击。 setOnItemLongClickListener 正在工作,但我无法让该行可点击。我看
我正在使用 Carl Bauer (https://github.com/bauerca/drag-sort-listview) 的优秀拖动排序 ListView 来实现启用拖动排序的 ListVie
我通过扩展 BaseExpandableListAdapter 来填充展开的 ListView 。 ChildView 的代码: public View getChildView(final int
我是一名优秀的程序员,十分优秀!