ListView控件,标记位置,用户触摸 [英] ListView, mark the position where the user touches

查看:119
本文介绍了ListView控件,标记位置,用户触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的列表视图 setOnTouchListener

view.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch(event.getAction()) {

            case MotionEvent.ACTION_DOWN:
                  view.setBackgroundColor(Color.parseColor("#f47920"));
                  break;

            case MotionEvent.ACTION_UP:
                  view.setBackgroundColor(Color.TRANSPARENT);
                  break; 

            }

            return false;
        }

    });

和我遇到了一个奇怪的问题:当用户拥有超过一个项目和手指拖动到下一个项目在列表视图中,previous项目将保持色彩,作为应用程序认为我尽量选择多个项目从列表。那么,如何去除颜色,如果用户按住一个手指拖动上下就行了?

And I ran into a strange problem: When the user holds over one item and drag the finger to an next item in the listview, the previous item will keep the color, as the application thinks that I try to select several items from the list. So how can I remove the color if the user holds down a finger and drags up and down on the list?

希望你们明白我尽力去完成。

Hope you guys understood what I try to accomplish.

推荐答案

什么是你的情况的看法?它是一个单独的列表项或主列表视图? 如果它是一个列表视图,然后尝试处理此案

What is the view in your case? Is it an individual list item or main listview ? If it is a listview, then try to handle the case

case MotionEvent.ACTION_MOVE : 
//Check position here, if it is out of your view, then change the color back.

这篇关于ListView控件,标记位置,用户触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆