This one seems to hassle developers who have just started using fragments. Take this scenario for example:

Main Container > View Pager > Fragment objects

The problem is when I put in 2 ViewPager objects dynamically in the main container via the FragmentManager and FragmentTransaction classes respectively. The option addToBackStack() is also included. Now, after the back key is pressed, the previous ViewPager should be displayed.

However, nothing is shown and that left me scratching my head for quite a few hours. The solution is to pass a ChildFragmentManager instance to the FragmentStatePagerAdapter constructor. Do not use FragmentManager as that will make it blank.

Also, make sure your adapter uses FragmentStatePagerAdapter instead of FragmentPagerAdapter.

With those 2 requirements on hand, your ViewPager should be displayed no matter where they are in the FragmentManager’s pop stack.

This had me confused for quite a while. It seems that the HttpClient for both Android and Apache works differently.

I tried to access a URL that contained unicode characters in it. What Apache’s version did was convert the unicode character into HTML code. For Android’s version, it converted it to this special glyph character showing a black diamond symbol and a question mark inside it.

This is how it looks like: �.

I have scoured through forums to see if there is a workaround for it and sadly I had found none. The closest explanation I found was that Android does not have a font that can understand and display the correct unicode symbol in the app.

Since my String value containing those characters are not a bunch of different unicode characters, what I did was use the replaceAll() method of the String class to convert these � symbols into the unicode symbol that I want.

The unicode for � is \uFFFD.

I thought at first there was something wrong with my code and it took me quite some time to figure out that there was nothing wrong with it. The problem lay in Android’s HttpClient class on how it handles unicode characters found in HTML pages.

This is how to simulate a back key press event in Android programmatically. Do note that this is called twice to dispatch a key event for both UP and down actions.

If only one of these two is executed, it will not work so make sure both of these are executed.

Related Posts Plugin for WordPress, Blogger...