Tag Archives: Mobile

Getting warning when calling getView() in Fragment

if you are getting below warning from compiler in your class where you are trying to create Fragment instance;

Warning: Method invocation ‘getView().findViewById(R.id.test)’ may produce ‘java.lang.NullPointerException’

Then chances are you are inflating your layout in onCreateView and trying to access layout elements outside that method.
Continue reading Getting warning when calling getView() in Fragment

Android: setting width and height programatically

There are times when you need to change width and height of View elements you defined in your XML layout or you want to create elements dynamically.
In that case you need to grab the view element and changed its layoutParams. Like how it is done below:

LinearLayout layout = (LinearLayout)findViewById(R.id.layoutId);
ViewGroup.LayoutParams params = layout.getLayoutParams();
params.width = 200;
params.height = 200;
layout.setLayoutParams(params);

Continue reading Android: setting width and height programatically

Ignoring SSl certificate when debugging in Android WebView

During development process if you are accessing a web page with SSL certificate you could either get a “Blank Page” or “Page Not Found” error.
To prevent this from happening while developing your app, simply override “onReceivedSslError” of WebViewClient object and continue the execution process.

By doing this, the SSL is being completely ignored and therefore could have a serious result if you forgot to remove the code after development and push the code into production.
To prevent that from happening simply check the build variants.

Adding shake effect in Android

To add a shake effect to a textbox when an error occurs, first add the following 2 XML files in your anim folder

< -- ../main/res/anim/shake.xml -->
1) Control how fast or slow the shake should be in this file.
2) Control how far the shake go from left to right.

Continue reading Adding shake effect in Android