Android 区分setOnClickListener和setOnTouchListener

Android 区分setOnClickListener和setOnTouchListener,android,onclick,imageview,viewflipper,ontouchlistener,Android,Onclick,Imageview,Viewflipper,Ontouchlistener,我需要一些帮助。在我的android应用程序中,我有一个包含一些线性布局的ViewFlipper。在每一条直线上,我都有一个图像视图。对于屏幕之间的切换,我使用以下代码: LinearLayout layMain = (LinearLayout) findViewById(R.id.layout_main); layMain.setOnTouchListener((OnTouchListener) this); //-------------- public boolean o

我需要一些帮助。在我的android应用程序中,我有一个包含一些线性布局的ViewFlipper。在每一条直线上,我都有一个图像视图。对于屏幕之间的切换,我使用以下代码:

LinearLayout layMain = (LinearLayout) findViewById(R.id.layout_main);
        layMain.setOnTouchListener((OnTouchListener) this);
//--------------

public boolean onTouch(视图arg0,运动事件arg1){
//获取在此触摸事件上执行的操作
开关(arg1.getAction()){
case MotionEvent.ACTION\u DOWN:{
//当按下用户的手指时,存储X值
downXValue=arg1.getX();
打破
}
case MotionEvent.ACTION\u UP:{
//获取用户释放手指时的X值
float currentX=arg1.getX();
//倒退:把东西往右边推
如果(向下X值<当前X){
//获取对ViewFlipper的引用
ViewFlipper vf=(ViewFlipper)findViewById(R.id.details);
//设置动画
vf.setOutAnimation(AnimationUtils.loadAnimation)(此,
R.anim.右推(右推);
vf.setInAnimation(AnimationUtils.loadAnimation)(此,
R.anim.推(右推);
//翻转!
vf.showPrevious();
}
//向前:把东西推到左边
如果(向下X值>当前X){
//获取对ViewFlipper的引用
ViewFlipper vf=(ViewFlipper)findViewById(R.id.details);
//设置动画
//vf.setInAnimation(AnimationUtils.loadAnimation)(此,
//R.anim.向左推(按);
vf.setOutAnimation(AnimationUtils.loadAnimation)(此,
R.anim.左推(出);
vf.setInAnimation(AnimationUtils.loadAnimation)(此,
R.anim.向左推(按);
//翻转!
vf.showNext();
}
打破
}
}
//如果返回false,则不会记录这些操作
返回true;
}
每个屏幕都包含一个ImageView。因此,当我切换屏幕时,ImageView正在改变。现在我想实现这一点:当点击一个图像时,就会打开一个url。这是我的密码:

ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);

        for (i = 0; i < jArray.length(); i++) {
            LinearLayout l = new LinearLayout(this);
            l.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT));
            l.setBackgroundColor(0x000000);
            l.setOrientation(LinearLayout.VERTICAL);
            vf.addView(l);

            ImageView img = new ImageView(this);
            img.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT));
            Drawable image1 = ImageOperations(getBaseContext(), url[i]);
            img.setImageDrawable(image1);
            System.out.println("target" + target[i]);
            img.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri
                            .parse("http://google.com"));
                    startActivity(browserIntent);
                }
            });

            l.addView(img);
        }
ViewFlipper vf=(ViewFlipper)findViewById(R.id.details);
对于(i=0;i
问题是每次我触摸屏幕时,url都是打开的,现在我无法在屏幕之间切换。如何做到这一点,以区别onClick()和on Touch()

请帮帮我。。
提前谢谢

我知道了你的问题,但问题是,对于切换屏幕,你应该使用,
Viewflipper
ontouch,比如:

 mFlipper.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
                     //// your touch code
而不是
Linearlayout触摸监听器

然后,您可以对Imageview事件使用
普通触摸监听器


希望对您有所帮助。

我认为您使用图像视图就像线性布局的背景一样,似乎活动处理ImageView的触摸,以实现您的功能setTouch listener for ImageView,我们可以使用OntouchListener中的以下代码间接处理单击图像视图

if (downXValue == currentX) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri
                        .parse("http://google.com"));
                startActivity(browserIntent);}

我为ViewFlipper设置了onTouchlistener,但没有任何更改。它在LinearLayout中的工作原理与以前一样。我所做的就是,在LinearLayout中,用脚蹼触摸切换..,,并在LinearLayout中用listview onitemclickfor切换listview,效果很好..listview没有onitemclickfor对不起…我误解了。我没有列表视图。我将imageview作为viewFlipper中线性布局的背景
if (downXValue == currentX) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri
                        .parse("http://google.com"));
                startActivity(browserIntent);}