Note that there are some explanatory texts on larger screens.

plurals
  1. POHow onFling works in viewSwitcher
    primarykey
    data
    text
    <p>I have 2 layouts inside a viewSwitcher, I need to change when I swipe that.</p> <pre><code>package slide.trys.one; import android.app.Activity; import android.os.Bundle; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.MotionEvent; import android.widget.ViewSwitcher; public class SlideActivity extends Activity implements OnGestureListener { private ViewSwitcher switcher; private GestureDetector gesturedetector = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); gesturedetector = new GestureDetector(this, this); } @Override public boolean onTouchEvent(MotionEvent event) { return gesturedetector.onTouchEvent(event); } int SWIPE_MIN_VELOCITY = 100; int SWIPE_MIN_DISTANCE = 100; public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) { float ev1X = e1.getX(); float ev2X = e2.getX(); final float xdistance = Math.abs(ev1X - ev2X); final float xvelocity = Math.abs(velocityX); if( (xvelocity &gt; SWIPE_MIN_VELOCITY) &amp;&amp; (xdistance &gt; SWIPE_MIN_DISTANCE) ) { if(ev1X &gt; ev2X) { switcher.showNext(); //Error in this part } else { switcher.showPrevious(); //Error in this part } } return false; } public void onLongPress(MotionEvent e) { } public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,float distanceY) { return false; } public void onShowPress(MotionEvent e) { } public boolean onSingleTapUp(MotionEvent e) { return false; } public boolean onDown(MotionEvent e) { return false; } } </code></pre> <p>I'm a newbie for java and Android too. pls help me, where am I doing mistake ? I getting error with <code>switcher.showNext()</code> and <code>switcher.showPrevious()</code> .</p> <p>pls help. the example I have is using android 4.0.3, But I need to work on 2.1. I don't know how to fix this.</p> <p>Will the viewSwitcher works on Android 2.1 ??</p> <p>my XML file.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;ViewSwitcher android:id="@+id/viewSwitcher" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inAnimation="@anim/in_animation" android:outAnimation="@anim/out_animation" &gt; &lt;RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;ImageView android:id="@+id/imageView2" android:contentDescription="@string/app_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/footer" /&gt; &lt;/RelativeLayout&gt; &lt;RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;ImageView android:id="@+id/imageView1" android:contentDescription="@string/app_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/blue_header" /&gt; &lt;/RelativeLayout&gt; &lt;/ViewSwitcher&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload