在scroll上调用Android ListView TouchListener

在scroll上调用Android ListView TouchListener,android,listview,scroll,ontouchlistener,Android,Listview,Scroll,Ontouchlistener,在我的项目中,我有一个ListView,它在getView中为每个视图提供了adapter方法 我的问题是当我滚动列表时,touchListener会激活 当用户滚动列表时,关于侦听器设置为getView()方法,我如何禁用触摸 谢谢 更新: 列表适配器中的代码如下所示: package com.example; import android.content.Context; import android.view.LayoutInflater; import android.view.

在我的项目中,我有一个
ListView
,它在
getView
中为每个视图提供了
adapter
方法

我的问题是当我滚动列表时,
touchListener
会激活

当用户滚动列表时,关于侦听器设置为
getView()
方法,我如何禁用触摸

谢谢

更新: 列表适配器中的代码如下所示:

  package com.example;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;


public class MyCustomAdapter extends BaseAdapter {
    private ArrayList<String> mListItems;
    private LayoutInflater mLayoutInflater;
    private Context context;

    public MyCustomAdapter(Context context, ArrayList<String> arrayList){

        mListItems = arrayList;

        //get the layout inflater
        mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.context = context;
    }

    @Override
    public int getCount() {
        //getCount() represents how many items are in the list
        return mListItems.size();
    }

    @Override
    //get the data of an item from a specific position
    //i represents the position of the item in the list
    public Object getItem(int i) {
        return null;
    }

    @Override
    //get the position id of the item from the list
    public long getItemId(int i) {
        return 0;
    }

    @Override

    public View getView(int position, View view, ViewGroup viewGroup) {

        //check to see if the reused view is null or not, if is not null then reuse it
        if (view == null) {
            view = mLayoutInflater.inflate(R.layout.list_item, null);
        }

        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent event) {
                Toast.makeText(context, "ON TOUCH ACTIVATED", 0).show();
                return true;
            }
        });

        //get the string item from the position "position" from array list to put it on the TextView
        String stringItem = mListItems.get(position);
        if (stringItem != null) {

            TextView itemName = (TextView) view.findViewById(R.id.list_item_text_view);

            if (itemName != null) {
                //set the item name on the TextView
                itemName.setText(stringItem);
            }
        }

        //this method must return the view corresponding to the data at the specified position.
        return view;

    }
}
package.com.example;
导入android.content.Context;
导入android.view.LayoutInflater;
导入android.view.MotionEvent;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.BaseAdapter;
导入android.widget.TextView;
导入android.widget.Toast;
导入java.util.ArrayList;
公共类MyCustomAdapter扩展了BaseAdapter{
私人阵列列表;
私人停车场平面布置;
私人语境;
公共MyCustomAdapter(上下文上下文,ArrayList ArrayList){
mListItems=阵列列表;
//找到布局充气机
mLayoutInflater=(LayoutInflater)context.getSystemService(context.LAYOUT\u INFLATER\u SERVICE);
this.context=上下文;
}
@凌驾
public int getCount(){
//getCount()表示列表中有多少项
返回mListItems.size();
}
@凌驾
//从特定位置获取项目的数据
//i表示项目在列表中的位置
公共对象getItem(int i){
返回null;
}
@凌驾
//从列表中获取项目的位置id
公共长getItemId(int i){
返回0;
}
@凌驾
公共视图getView(内部位置、视图视图、视图组视图组){
//检查重用的视图是否为null,如果不为null,则重用它
如果(视图==null){
视图=MLAyoutFlater.充气(R.layout.list\u项,空);
}
view.setOnTouchListener(新的view.OnTouchListener(){
@凌驾
公共布尔onTouch(视图、运动事件){
Toast.makeText(上下文,“触控激活”,0.show();
返回true;
}
});
//从数组列表中的位置“position”获取字符串项,将其放在TextView中
String stringItem=mListItems.get(位置);
如果(stringItem!=null){
TextView itemName=(TextView)view.findViewById(R.id.list\u item\u text\u view);
if(itemName!=null){
//在TextView上设置项目名称
itemName.setText(stringItem);
}
}
//此方法必须返回与指定位置的数据对应的视图。
返回视图;
}
}

我终于解决了我的问题,在xml布局中添加了ListView,其中ListView声明为
android:DegenantFocusability=“BlocksDescents”
,它现在可以工作了。

为什么不使用
onClick
而不是
onTouch
?安卓平台有这个列表的内置属性,所以你的代码有问题。请编辑问题并输入代码。我已使用自定义适配器中的代码编辑了我的答案。我尝试为onTouchListener返回false和true,但没有结果:(.我从中获得了listview的代码,我将侦听器放置在触摸屏上,如果你想测试和查看发生了什么,你也可以从那里获得代码。你真的应该考虑在
listview
OnClickListener
的每个
视图上使用
OnClickListener
。问题是我没有o使用onTouchListener,因为我需要MotionEvent用于我必须实现的下一个功能。