Can I use view pager with views (not with fragments)

You need to override these two methods rather than getItem(): @Override public Object instantiateItem(ViewGroup collection, int position) { View v = layoutInflater.inflate(…); … collection.addView(v,0); return v; } @Override public void destroyItem(ViewGroup collection, int position, Object view) { collection.removeView((View) view); }

Why is accessing TextView of a Fragment inside Activity throwing an error

Because fo hasn’t been initialized in the following code snippet: FragOne fo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); fo.setTextViewText(“This is added from Activity”); … } fo.setTextViewText() reasonably throws NPE.

ViewPager OnItemClickListener

There is no OnItemClick callback method for ViewPager. If you want click events on each page then you’ll have to build your listener into the page content within your Adapter. something like this: @Override public Object instantiateItem(View collection, final int pos) { //have to make final so we can see it inside of onClick() LayoutInflater … Read more

Android ViewPager with bottom dots

No need for that much code. You can do all this stuff without coding so much by using only viewpager with tablayout. Your main Layout: <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:layout_width=”match_parent” android:layout_height=”wrap_content”> <android.support.v4.view.ViewPager android:id=”@+id/pager” android:layout_width=”match_parent” android:layout_height=”match_parent”> </android.support.v4.view.ViewPager> <android.support.design.widget.TabLayout android:id=”@+id/tabDots” android:layout_alignParentBottom=”true” android:layout_width=”match_parent” android:layout_height=”wrap_content” app:tabBackground=”@drawable/tab_selector” app:tabGravity=”center” app:tabIndicatorHeight=”0dp”/> </RelativeLayout> Hook up your UI elements inactivity or fragment as follows: Java … Read more

refresh fragment UI from fragmentActivity

So obviously adjust for your specific needs, but this is what I use for my Application. Fragment frag = getSupportFragmentManager().findFragmentByTag(“android:switcher:” + R.id.pager + “:” + mPager.getCurrentItem()); if(frag!=null&&mPager.getCurrentItem()==0) { ((Fragment1) frag).changeImageView(1); }

How do you get the current page number of a ViewPager for Android?

in the latest packages you can also use vp.getCurrentItem() or vp is the viewPager , pageListener = new PageListener(); vp.setOnPageChangeListener(pageListener); you have to put a page change listener for your viewPager. There is no method on viewPager to get the current page. private int currentPage; private static class PageListener extends SimpleOnPageChangeListener{ public void onPageSelected(int position) … Read more

How can make my ViewPager load only one page at a time ie setOffscreenPageLimit(0);

I was having the same problem and I found the solution for it: Steps: 1) First Download the CustomViewPager Class from this link. 2) Use that class as mentioned below: In Java: CustomViewPager mViewPager; mViewPager = (CustomViewPager) findViewById(R.id.swipePager); mViewPager.setOffscreenPageLimit(0); In XML: <com.yourpackagename.CustomViewPager xmlns:android=”http://schemas.android.com/apk/res/android” android:id=”@+id/swipePager” android:layout_width=”match_parent” android:layout_height=”match_parent”/> Now only one page will be loaded at once. … Read more

Can ViewPager have multiple views in per page?

I discovered that a perhaps even simpler solution through specifying a negative margin for the ViewPager. I’ve created the MultiViewPager project on GitHub, which you may want to take a look at: https://github.com/Pixplicity/MultiViewPager Although MultiViewPager expects a child view for specifying the dimension, the principle revolves around setting the page margin: ViewPager.setPageMargin( getResources().getDimensionPixelOffset(R.dimen.viewpager_margin)); I then … Read more

ViewPager with Google Maps API v2: mysterious black view

I was able to stop the black surface being left behind after transition by placing another view with a transparent background on top of the ViewPager inside a FrameLayout: <FrameLayout android:layout_width=”match_parent” android:layout_height=”match_parent” > <android.support.v4.view.ViewPager android:id=”@+id/fragment_container” android:layout_width=”match_parent” android:layout_height=”match_parent” > </android.support.v4.view.ViewPager> <!– hack to fix ugly black artefact with maps v2 –> <FrameLayout android:layout_width=”match_parent” android:layout_height=”match_parent” android:background=”@android:color/transparent” /> … Read more

How do you create a transparent demo screen for an Android app?

Put your demo info in a different activity and give it the following theme. <style name=”Transparent” parent=”@android:style/Theme.NoTitleBar”> <item name=”android:windowContentOverlay”>@null</item> <item name=”android:windowIsTranslucent”>true</item> <item name=”android:windowBackground”>@android:color/transparent</item> <item name=”android:windowNoTitle”>true</item> <item name=”android:backgroundDimEnabled”>false</item> </style> If you’re using ActionBarSherlock change parent to @style/Theme.Sherlock. This will give you a transparent activity, so you will be able to see the activity below it. Now … Read more

tech