Note that there are some explanatory texts on larger screens.

plurals
  1. POViewPager won't scroll to next page
    primarykey
    data
    text
    <p>I have a FragmentActivity that has tabs in it. The first tab has a ViewPager in it. The ViewPager does not work. It displays the first page, but will not scroll to the next page. I saw the instantiateItem get called for the next page. I think maybe the touch is being intercepted by something else, not quite sure.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tabHost" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;LinearLayout android:id="@+id/main" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:src="@drawable/topbanner" /&gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;LinearLayout android:id="@+id/hometab" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;android.support.v4.view.ViewPager android:id="@+id/product_viewpager" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; &lt;ScrollView android:id="@+id/scroller" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true" &gt; &lt;LinearLayout android:id="@+id/articlestab" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; &lt;LinearLayout android:id="@+id/videostab" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/txt3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="This is tab 3" /&gt; &lt;/LinearLayout&gt; &lt;/FrameLayout&gt; &lt;/LinearLayout&gt; &lt;/TabHost&gt; </code></pre> <p>And here is the image_page that I put into the ViewPager, I add 6 of them.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/image_page" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/border" android:orientation="horizontal" &gt; &lt;ImageView android:id="@+id/image" android:layout_width="100dip" android:layout_height="100dip" android:layout_gravity="center_vertical" android:src="@drawable/app" /&gt; &lt;TextView android:id="@+id/caption" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Title" android:textStyle="bold" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>here is where I add the adapter:</p> <pre><code> MyPagerAdapter adapter = new MyPagerAdapter(); ViewPager myPager = (ViewPager) findViewById(R.id.product_viewpager); myPager.setAdapter(adapter); myPager.setCurrentItem(0); </code></pre> <p>Here is the adapter:</p> <pre><code>private class MyPagerAdapter extends PagerAdapter { public int getCount() { return 6; } public Object instantiateItem(View collection, int position) { String image = null; String caption = null; Log.d(TAG, "instantiateItem called for position: " + position); if (sliderResults != null) { LinearLayout layout1 = null; LayoutInflater inflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); JSONArray jArray = null; try { jArray = new JSONArray(sliderResults); JSONObject j = jArray.getJSONObject(0); layout1 = (LinearLayout) inflater.inflate(R.layout.image_page, null); switch (position) { case 0: image = "img1"; caption = "capt1"; break; case 1: image = "img2"; caption = "capt2"; break; case 2: image = "img3"; caption = "capt3"; break; case 3: image = "img4"; caption = "capt4"; break; case 4: image = "img5"; caption = "capt5"; break; case 5: image = "img6"; caption = "capt6"; break; } new DownloadImageTask((ImageView) layout1.findViewById(R.id.image), 100).execute("http://removed" + j.getString(image)); ((TextView) layout1.findViewById(R.id.caption)).setText(j.getString(caption)); } catch (JSONException e) { Log.d(TAG, "JSONException"); e.printStackTrace(); } // View view = inflater.inflate(resId, null); ((ViewPager) collection).addView(layout1, 0); return layout1; }else{ Log.d(TAG, "slider results not ready yet"); } return null; } @Override public void destroyItem(View arg0, int arg1, Object arg2) { ((ViewPager) arg0).removeView((View) arg2); } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == ((View) arg1); } @Override public Parcelable saveState() { return null; } } </code></pre> <p>I created a test view activity with the same code and the ViewPager works. It has something to do with the TabHost I believe. Maybe it is interception the touch events or something?</p>
    singulars
    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