如何使列表的页眉和页脚没有点击能? [英] How to make list header and footer not click able?
本文介绍了如何使列表的页眉和页脚没有点击能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个页脚和页眉列表。我添加onLongClick从列表中删除的项目。当我长美元接头连接器P $ PSS从列表中删除第一个项目。当我点击最后一个项目或页脚的应用程序将crash-项目超出范围。
我可以页脚和页眉无法点击?或者我应该如何在适配器数项?或者是有一些其他的方式来baypass呢?
删除项目:
块引用>
块引用>list.setOnItemLongClickListener(新OnItemLongClickListener(){
公共布尔onItemLongClick(适配器视图<>母公司,视图V,
INT位置,长的id){
//从列表中删除项目 ShoppingItem simpleItem = NULL; 如果(shoppingListApplication.getAdapter()的getCount()方式> 0){
simpleItem =(ShoppingItem)shoppingListApplication
。.getAdapter()的getItem(位置);
removeShoppingItem(simpleItem,
shoppingListApplication.getAdapter()); }
解决方案在HeaderView
和FooterView
有关独立的上下文菜单的>的ListView
。@覆盖
公共无效onCreateContextMenu(文本菜单菜单视图V,ContextMenuInfo menuInfo){
super.onCreateContextMenu(菜单,V,menuInfo);
MenuInflater吹气= getMenuInflater(); 如果(((AdapterContextMenuInfo)menuInfo).POSITION == 1){
inflater.inflate(R.menu.foo1,菜单); //标题菜单
返回;
}
否则如果(((AdapterContextMenuInfo)menuInfo).POSITION == listView.getAdapter()。的getCount()+ 1){
inflater.inflate(R.menu.foo2,菜单); //页脚菜单
返回;
}
inflater.inflate(R.menu.foo3,菜单);
}I have a list with footer and header. I added onLongClick to delete item from list. When I press long on header it remove first item from list. When I click on last item or footer the app will crash- item out of range.
Can I make footer and header not clickable? or how should i count item in adapter? or is there some other way to baypass it?
Removing items:
list.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) { // Delete Item from List ShoppingItem simpleItem = null; if (shoppingListApplication.getAdapter().getCount() > 0) { simpleItem = (ShoppingItem) shoppingListApplication .getAdapter().getItem(position); removeShoppingItem(simpleItem, shoppingListApplication.getAdapter()); }
解决方案For Seperate Context menu in
HeaderView
andFooterView
ofListView
.@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater = getMenuInflater(); if (((AdapterContextMenuInfo)menuInfo).position == 1) { inflater.inflate(R.menu.foo1, menu); // HEADER MENU return; } else if(((AdapterContextMenuInfo)menuInfo).position == listView.getAdapter().getCount() + 1) { inflater.inflate(R.menu.foo2, menu); // FOOTER MENU return; } inflater.inflate(R.menu.foo3, menu); }
这篇关于如何使列表的页眉和页脚没有点击能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文