ListView无法响应OnTouch事件

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent" android:id="@+id/ll">
	<TextView android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:text="@string/hello"></TextView>
	<RadioGroup android:id="@+id/type_radio_group"
		android:layout_width="wrap_content" android:orientation="horizontal"
		android:layout_gravity="center" android:layout_height="wrap_content"
		android:checkedButton="@+id/type_departure_radio" android:background="@color/blue">
		<RadioButton android:id="@+id/type_departure_radio">
		</RadioButton>
		<RadioButton android:id="@+id/type_arrival_radio">
		</RadioButton>
	</RadioGroup>
	<ListView android:layout_width="fill_parent"
		android:background="@color/gray" android:id="@+id/list_punctuality_arrival"
		android:layout_height="wrap_content"></ListView>
	<ViewFlipper android:id="@+id/flipper_punctuality"
		android:layout_width="fill_parent" android:layout_height="fill_parent">
		<TextView android:layout_width="fill_parent"
			android:layout_height="wrap_content" android:text="@string/hello" />
	</ViewFlipper>
</LinearLayout> 
Activity.java

package com.shimly.gesture;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

public class GestureTestActivity extends Activity implements OnTouchListener,
		OnGestureListener {
	GestureDetector mGestureDetector;
	private static final int FLING_MIN_DISTANCE = 50;
	private static final int FLING_MIN_VELOCITY = 0;
	ListView list_punctuality_arrival;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		list_punctuality_arrival = (ListView) findViewById(R.id.list_punctuality_arrival);
		mGestureDetector = new GestureDetector(this);
		LinearLayout ll = (LinearLayout) findViewById(R.id.ll);
		ll.setOnTouchListener(this);
		ll.setLongClickable(true);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, new String[] { "a", "b" });
		list_punctuality_arrival.setAdapter(adapter);
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		Log.e("touch", "touch");
		return mGestureDetector.onTouchEvent(event);
	}

	@Override
	public boolean onDown(MotionEvent e) {
		return false;
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		if (e1.getX() - e2.getX() > FLING_MIN_DISTANCE
				&& Math.abs(velocityX) > FLING_MIN_VELOCITY) {
			Toast.makeText(this, "left", Toast.LENGTH_SHORT).show();
		} else if (e2.getX() - e1.getX() > FLING_MIN_DISTANCE
				&& Math.abs(velocityX) > FLING_MIN_VELOCITY) {
			Toast.makeText(this, "right", Toast.LENGTH_SHORT).show();
		}
		return false;
	}

	@Override
	public void onLongPress(MotionEvent e) {
	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {
		return false;
	}

	@Override
	public void onShowPress(MotionEvent e) {
	}

	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		return false;
	}
}

效果是,listview不响应OnTouch事件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值