Java Android ExpandedListView希望SwipeToDismiss只在组上工作
我从这里得到了SwipeToDismiss实现的实际版本: 而且效果很好。但是,我在ExpandedListView上使用它,我只希望组是可忽略的 在TouchListener事件中,我可以在两个地方进行干预,不允许解雇:Java Android ExpandedListView希望SwipeToDismiss只在组上工作,java,android,Java,Android,我从这里得到了SwipeToDismiss实现的实际版本: 而且效果很好。但是,我在ExpandedListView上使用它,我只希望组是可忽略的 在TouchListener事件中,我可以在两个地方进行干预,不允许解雇: mListView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { // re
mListView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
// return false if not on a group ???????
return mSwipeDismissTouchListener.onTouch(view, motionEvent);
..
mSwipeDismissTouchListener = new SwipeDismissListViewTouchListener(
mListView,
new SwipeDismissListViewTouchListener.DismissCallbacks() {
public boolean canDismiss(int position) {
// return false if not on a group ???????
}
public void onDismiss(ListView listView, int[] reverseSortedPositions) {
}
}
);
或在SwipedSmissListViewTouchListener事件中:
mListView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
// return false if not on a group ???????
return mSwipeDismissTouchListener.onTouch(view, motionEvent);
..
mSwipeDismissTouchListener = new SwipeDismissListViewTouchListener(
mListView,
new SwipeDismissListViewTouchListener.DismissCallbacks() {
public boolean canDismiss(int position) {
// return false if not on a group ???????
}
public void onDismiss(ListView listView, int[] reverseSortedPositions) {
}
}
);
但我不知道如何判断点击/触摸事件是否发生在某个组或儿童身上
有人有什么想法吗
TIA。好的,我想我已经解决了,尽管感觉有点不舒服: 在适配器中,我为getChildView和GetGroupView添加了一个触摸式侦听器,这允许我保留当前所选项目的类型
然后,在事件处理程序中包含扩展列表视图的视图中,我只需询问列表适配器当前接触的对象是否为组,如果是,则允许刷卡即可。您需要采用适配器类作为用途,但需要做一些修改:将其公开,将字段公开,类似这样的事情
public static class ViewHolderGroup {
TextView tvName;
ImageView ivLogo;
public boolean isGroup;
}
并将一些变量设置为,这将定义wheater
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ViewHolderGroup holder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row_group_operator, null);
holder = new ViewHolderGroup();
holder.tvName = (TextView) convertView.findViewById(R.id.layout_row_group_operator_tv_Name);
holder.ivLogo = (ImageView) convertView.findViewById(R.id.layout_row_group_operator_iv_Logo);
holder.ivLogo.setVisibility(View.GONE);
holder.isGroup = true; // Here we setting field to know this is group
convertView.setTag(holder);
} else {
holder = (ViewHolderGroup) convertView.getTag();
}
....
}
然后在前面描述的代码中获取此标记,如下所示
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
fa = this;
View rootView = inflater.inflate(R.layout.fg_elist, container, false);
final ExpandableListView elMain = (ExpandableListView) rootView.findViewById(R.id.layout_fg_elist_elv_Main);
RouteExpandableListAdapter routesAdapter = new RouteExpandableListAdapter(Rendis.mContext, Rendis.dates, Rendis.routes);
elMain.setAdapter(routesAdapter);
registerForContextMenu(elMain);
elMain.setOnChildClickListener(this);
elMain.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent motionEvent) {
Rect rect = new Rect();
int childCount = elMain.getChildCount();
int[] listViewCoords = new int[2];
elMain.getLocationOnScreen(listViewCoords);
int x = (int) motionEvent.getRawX() - listViewCoords[0];
int y = (int) motionEvent.getRawY() - listViewCoords[1];
View child;
for (int i = 0; i < childCount; i++) {
child = elMain.getChildAt(i);
child.getHitRect(rect);
if (rect.contains(x, y)) {
RouteExpandableListAdapter.ViewHolderGroup holder = (RouteExpandableListAdapter.ViewHolderGroup) child.getTag();
if(holder.isGroup){
// DO WHAT YOU WANT TO DO
}
break;
}
}
return false;
}
});
return rootView;
}
@覆盖
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
fa=这个;
视图根视图=充气机。充气(R.layout.fg_elist,container,false);
最终可扩展列表视图elMain=(可扩展列表视图)rootView.findViewById(R.id.layout\u fg\u elist\u elv\u Main);
RouteExpandableListAdapter RouteAdapter=新的RouteExpandableListAdapter(Rendis.mContext、Rendis.dates、Rendis.routes);
elMain.setAdapter(路由适配器);
registerForContextMenu(elMain);
elMain.setOnChildClickListener(这个);
elMain.setOnTouchListener(新视图.OnTouchListener(){
@凌驾
公共布尔onTouch(视图v,MotionEvent){
Rect Rect=新的Rect();
int childCount=elMain.getChildCount();
int[]listViewCoords=新int[2];
elMain.getLocationOnScreen(listViewCoords);
int x=(int)motionEvent.getRawX()-listViewCoords[0];
int y=(int)motionEvent.getRawY()-listViewCoords[1];
看孩子;
for(int i=0;i
希望这能有所帮助