Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何为视图列表设置OnTouchListener?_Android_Textview - Fatal编程技术网

Android 如何为视图列表设置OnTouchListener?

Android 如何为视图列表设置OnTouchListener?,android,textview,Android,Textview,求你了,我需要帮助。我想为视图表中的每个视图设置OnTouchListener。 这是我的密码: for(TextView tv : getChoices()){ ChoicesLayout.addView(tv); } getChoices方法返回一个TextView数组。我想为每个文本视图设置OnTouchListener,然后将其添加到布局中。 有人能帮帮我吗 我试过这个: for(TextView tv : getChoices()){ tv.setOnTouchListene

求你了,我需要帮助。我想为视图表中的每个视图设置OnTouchListener。 这是我的密码:

for(TextView tv : getChoices()){
    ChoicesLayout.addView(tv);
}
getChoices方法返回一个TextView数组。我想为每个文本视图设置OnTouchListener,然后将其添加到布局中。 有人能帮帮我吗

我试过这个:

for(TextView tv : getChoices()){
tv.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getAction()==MotionEvent.ACTION_DOWN){
                ClipData data = ClipData.newPlainText("", "");
                DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
                // Start dragging the item
                v.startDrag(data, shadowBuilder, v, 0);
                return true;
            }else{
                return false;
            }

        }
    });
    ChoicesLayout.addView(tv);
}

但是它不起作用。

我不知道你是如何实现你的文本视图列表的,但我猜它是在列表视图中

您可以尝试在ImageAdapter中添加OnTouch


这有点。我希望我能提供帮助

您能告诉我们您在设置OnTouchListener方面做了哪些尝试吗?您能将其编辑到您的问题中,以便其他人能清楚地看到吗?它可能会让更多的人看到这一点,从而能够帮助你。