JavaScript: Clear ListView or all contents in a div

If  you need to all items in a HTML ListView or div using JavaScript, below is a useful function to do so.
The function basically get the element and if the element exist proceed to remove all of its child nodes.

function ClearList(listId) {
    var el = document.getElementById(listId)

    if (el) {
        while (el.hasChildNodes()) {
            el.removeChild(el.childNodes[0]);
        }
    }
}
JavaScript: Clear ListView or all contents in a div

JavaScript/JQuery: Open/Close Popup

I was having this problem the other where I was using JQuery Mobile popup but I couldn’t close/open it dynamically using JavaScript. Below is the syntax solution to this problem.

This was my popup html tag

...
<div data-role="popup" id="popupLocation" data-theme="a" style="padding: .5em .5em .5em .5em; min-width:20em;">
   <div id="div-location-back-btn">
      <button data-icon="carat-l" onclick="RaiseEvent('TRAVERSE-UP-LOCATION')" data-inline="true">Back</button>
   </div>
   <ul id="location-tree" data-role="listview" data-filter="true" data-filter-placeholder="Search location" data-inset="true" style="min-width:210px;"></ul>
</div>
...

JavaScript function to open popup.

function OpenPopup(popupId) {
   $('#' + popupId).popup('open');
}

JavaScript: Function to close popup.

function ClosePopup(popupId) {
   $('#' + popupId).popup('close');
}
JavaScript/JQuery: Open/Close Popup

Xamarin Adroid: Retain Instance of Webview Content On Rotation

I’m developing an android hybrid app using C# in VS 2013. The app make use of WebView which was giving me problem with rotation. Every time the screen rotate from landscape to portrait the app will auto refresh to back login page. After googling a bit, I found that when screen orientation change android’s activity will refresh. Hence, I need to save the instance of WebView when the activity about to get refresh on screen orientation change and reload the save WebView when the activity reinitialize.

This is the URL to source of the solution: http://twigstechtips.blogspot.com/2013/08/android-retain-instance-of-webview.html

The URL above gave the fix in Java. Below is my converted version to C# when using Xamarin.

1.   Add ConfigurationChanges setting to the activity. In Solution above, it was added to the manifest xml however, I find that in Xamarin C# you can just add it in to the Activity tag.

[Activity(Label = Global.Config.MainLabel, MainLauncher = true, Icon = "@drawable/icon", Theme = Global.Config.MainTheme, ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.KeyboardHidden | Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
public class MainActivity : Activity
{

2. Override Activity.onSaveInstanceState() and save the state of the webview in this method. FYI, I stored my WebView in Html class.

/// <summary>
/// Handles when Main Activity needed to be refreshed e.g screen rotation
/// </summary>
protected override void OnSaveInstanceState(Bundle outState)
{
    base.OnSaveInstanceState(outState);
    // Save WebView State
    Html.wv.SaveState(outState);
}

3. Load save WebView state (if any) in OnCreate function.

protected override void OnCreate(Bundle savedInstanceState)
{
   base.OnCreate(savedInstanceState);
   SetContentView(Resource.Layout.Main);
   WebView wv = FindViewById<WebView>(Resource.Id.localWebView);

   if (savedInstanceState != null)
   {
       // Restore WebView saved state (if any)
       wv.RestoreState(savedInstanceState);
       Html.wv = wv;
       Html.context = this;
   }
   else
   {
       // Initialize WebView
       wv.SetWebChromeClient(new HybridWebChromeClient(this));
       Html.Initialize(this, wv);
       new AppLogin().Show();
   }
}

This is very simple solution to implement. Hope it helps.

Xamarin Adroid: Retain Instance of Webview Content On Rotation