Below you will find pages that utilize the taxonomy term “Mobile”
Posts
Showing static HTML in WebView - Android
Loading a live web page from the internet into Webview object is straight forward.
The simplest way is to create a Webview object and load URL into the object:
<pre class="lang:java decode:true ">webview.loadUrl("http://your-website.com/"); But what if you need to show a custom HTML page to your users?
For a simple static page you can create a HTML document in a string variable and load it into Webview object:
<pre class="lang:java decode:true ">String welcome = "Welcome <em>John</em>!
Posts
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.
For example,
<pre class="wp-block-code">```java public class fragmentTest extends Fragment { @Override public void onActivityCreated(Bundle bundle) { super.onActivityCreated(bundle); TextView text = (textView) getView().findViewById(R.id.test); // ... } @Override public View onCreateView ( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.
Posts
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);<br></br>ViewGroup.LayoutParams params = layout.getLayoutParams();<br></br>params.width = 200;<br></br>params.height = 200;<br></br>layout.setLayoutParams(params);
Notice that params.width values are in pixels. If you need your dimensions in DP or SP units you need to convert it.
Posts
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.
Posts
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
1) Control how fast or slow the shake should be in this file.
2) Control how far the shake go from left to right.
<pre class="lang:java decode:true "><translate xmlns:android="http://schemas.android.com/apk/res/android" android:fromXDelta="0%" android:toXDelta="1%" android:duration="500" android:interpolator="@anim/cycle" /> Control how many times you want the shake animation to occur.
<pre class="lang:default decode:true "><cycleInterpolator xmlns:android="http://schemas.