ListView控件,标记位置,用户触摸控件、标记、位置、用户

由网友(不吵不闹不炫耀)分享简介:我有一个自定义的列表视图与 setOnTouchListener view.setOnTouchListener(new OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {switch(event.getAc...

我有一个自定义的列表视图 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.
阅读全文

相关推荐

最新文章