Search This Blog

Monday, 28 October 2013

ViewPager android Fact and constraint about offscreen page limit

ViewPager inbuilt swipe animation is very good. ViewPager exist for a reason with HorizontalScrollView(Which scroll the content in same manner but different methodologies). ViewPager used for swiping content on the base of keep ready next content to be swipe. And its whole limitation and strength, which developer feels some times, lie in that.

How many (i.e Minimum and Maximum) page of ViewPager may be preloaded?

setOffscreenPageLimit(1); decide how many page to be preloaded. As i am not sure about what is the maximum limit for it but minimum is 1. setting off screen page limit to 0 does nothing except throwing  warning in LogCat Requested offscreen page limit 0 too small; defaulting to 1Its because ViewPager is based on concept of keep ready next page to be loaded. ViewPager can not the page which not exist still. Android documentation of ViewPager clearly. But most developer feels its not what they required. Then you have option with some work around there but you can not change ViewPager behavior.

Some people argue that they want to load empty instance of fragment as part of child of ViewPager then later on full content. You are free to do  but you will be solely responsible to handle its complications.

onPageListner gives you a way but its bit of tricky to handle.


I absolutely agree with ViewPager's documentation. There must be some content exist before swiping it down. You can use an in out animation if you do not want to customize ViewPager. But being with Adapter, ViewPager allow you to recyling of View

Thursday, 24 October 2013

Volley Android Networking Library : How to use Volley in your application and why?

In 2013 I/O Android session Ficus Kirkpatrick launched a new support for android developer. This is really cool library for networking operation.
If being android developer you stuck and searching for many question's answer related networking connection. Volley android sdk Gives the answer

Volley fixed these problems

1) All network requests happen serially
2) Rotating the screen will reload everything from the network
3) AsyncTasks stomp on recycled views
4) Compatibility problems on Froyo

Then curiously how's the documentation of android volley going to be !!Answer is Very simple

Volley Android library Implementation


Initializing Volley android before use anywhere in Constructer which called very first time


 // Somewhere common; app startup or adapter constructor  
 mRequestQueue = Volley.newRequestQueue(context);  
 mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache());  

Making request to URL which gives Json Response


 mRequestQueue.add(new JsonObjectRequest(Method.GET, url, null,  
 new Listener<JSONObject>() {  
 public void onResponse(JSONObject jsonRoot) {  
 mNextPageToken = jsonGet(jsonRoot, "next", null);  
 List<Items> items = parseJson(jsonRoot);  
 appendItemsToList(item);  
 notifyDataSetChanged();  
 }  
 }  
 }  

Image Loading through volley contain two way

  •  Using ImageLoader class
 mImageLoader.get(image_url,imageView, R.drawable.loading, R.drawable.error);  
  • Using Volley Android Custom ImageView
 - <ImageView  
 + <com.android.volley.NetworkImageView  
 Java mImageView.setImageUrl(BASE_URL + item.image_url, mImageLoader);  

There are a lot more in Volley android. Download Sample and check them out
Android News and source code