<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>moneyback Archives - CodeJourney.net</title>
	<atom:link href="https://www.codejourney.net/tag/moneyback/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codejourney.net/tag/moneyback/</link>
	<description>Pragmatic full stack software development</description>
	<lastBuildDate>Tue, 17 Dec 2019 00:03:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://i0.wp.com/www.codejourney.net/wp-content/uploads/2018/10/cropped-512px-na-512px-JPEG-BEZ-NAPISU-1.jpg?fit=32%2C32&#038;ssl=1</url>
	<title>moneyback Archives - CodeJourney.net</title>
	<link>https://www.codejourney.net/tag/moneyback/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">123174533</site>	<item>
		<title>Xamarin.Android &#8211; ASP.NET web api synchronization &#8211; research</title>
		<link>https://www.codejourney.net/xamarin-android-asp-net-web-api-synchronization-research/</link>
					<comments>https://www.codejourney.net/xamarin-android-asp-net-web-api-synchronization-research/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Wed, 27 Sep 2017 06:00:45 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[asp-net-core]]></category>
		<category><![CDATA[moneyback]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=2345</guid>

					<description><![CDATA[<p>As you may know, in my MoneyBack Xamarin.Android application I&#8217;ve used SQLite as the local db management system. Recently I&#8217;ve added an ASP.NET Core web solution to my GitHub repository in order to create back-end API for my mobile app. I wanted to have database hosted on a remote server and Android application to synchronize its data&#8230;</p>
<p>The post <a href="https://www.codejourney.net/xamarin-android-asp-net-web-api-synchronization-research/">Xamarin.Android &#8211; ASP.NET web api synchronization &#8211; research</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>As you may know, in my <a href="https://github.com/dsibinski/MoneyBack" target="_blank" rel="noopener noreferrer">MoneyBack</a> Xamarin.Android application I&#8217;ve used <a href="https://www.codejourney.net/2017/03/using-sqlite-database-in-xamarin-android/" target="_blank" rel="noopener noreferrer">SQLite</a> as the local db management system. Recently I&#8217;ve added an <a href="https://github.com/dsibinski/MoneyBack.Web" target="_blank" rel="noopener noreferrer">ASP.NET Core web solution to my GitHub repository</a> in order to create back-end API for my mobile app. I wanted to have database hosted on a remote server and Android application to synchronize its data with it.<br />
Then I started wondering&#8230; and decided to make a deeper research first. As I wrote in <a href="https://www.codejourney.net/2017/05/dajsiepoznac2017-summary/" target="_blank" rel="noopener noreferrer">my post summing up DajSiePoznac2017 competition</a>, &#8220;before using a particular solution for an issue&#8221; we should &#8220;better examine the other possibilities&#8221; first. So I do <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /><br />
<span id="more-2345"></span></p>
<h2>Why to synchronize with remote database?</h2>
<p>First question to ask is <strong>why to synchronize with a remote database at all</strong>?</p>
<h6>There are a few obvious advantages:</h6>
</p>
<p><strong>(+)</strong> users&#8217; data is stored &#8220;in a cloud&#8221; and can be accessed from any device</p>
<p><strong>(+)</strong> users don&#8217;t need to worry about backing-up their data</p>
<p><strong>(+)</strong> data storage logic is moved to the web part of the system and with API exposed it can be easier to port it to other platforms</p>
<p><strong>(+)</strong> having web API, a web client can be easily added to the system.</p>
<h6>However, there are also some harms:</h6>
<p><strong>(-)</strong> synchronization of local and remote data (online and offline) must be handled</p>
<p><strong>(-)</strong> synchronization uses some network data and battery of a mobile device</p>
<p><strong>(-) </strong>web API must be maintained and after each change in it mobile app must be adjusted.</p>
<p>Despite all these aspects I&#8217;ve been wondering to implement a web API for few different reasons. First of all this could be a great programming experience, very interesting from architectural point of view. Secondly, I think this is a bit old-fashioned and messy that a user needs to export some database/app files backup to his GDrive in order to not lose his data.</p>
<p>Frankly, I just want to have some fun with ASP.NET Core, implement a web API and make <a href="https://github.com/dsibinski/MoneyBack" target="_blank" rel="noopener noreferrer">MoneyBack</a> working with it <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Maybe some Linux deployment after all? Let&#8217;s create some nice programming playground <a href="https://github.com/dsibinski/MoneyBack/tree/master/Web" target="_blank" rel="noopener noreferrer">here</a> <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h2>How to synchronize with web API?</h2>
<p>That&#8217;s the question I&#8217;ve been searching an answer for recently. Long story short, the idea is to have a <strong>back-end database management system hosted on a web server</strong> and mobile app having its own local &#8220;mirror&#8221; of the database, <strong>bidirectionally synchronizing local data with remote database through web API</strong>. Mobile app should work in <strong>offline-first</strong> mode, which means that all operations must be possible to be done locally and potential (not mandatory) synchronization to happen as soon as it&#8217;s possible (user is connected to WiFi, has mobile network access etc.)</p>
<p>There are various possibilities and solutions to handle synchronization of mobile app&#8217;s data and remote database storage, from synchronization system built from scratch to Azure cloud hosting.</p>
<h4>Custom synchronization mechanism</h4>
<p>We could of course implement our own data synchronization mechanism. There are many tutorials available, including for instance <a href="https://xamarinhelp.com/mobile-database-bi-directional-synchronization-rest-api/" target="_blank" rel="noopener noreferrer">this one</a>, which describes all the contents quite nicely and I recommend reading it even if you don&#8217;t want to implement sync on your own &#8211; it helps understanding all the concepts.</p>
<p>Custom synchronization can be a lot of fun, but&#8230; why to reinvent the wheel?</p>
<h4>Azure Mobile App Service</h4>
<p><a href="https://azure.microsoft.com/en-us/services/app-service/mobile/" target="_blank" rel="noopener noreferrer">Microsoft&#8217;s Azure Mobile App Service</a> is recommended almost everywhere &#8211; <a href="https://stackoverflow.com/questions/33224792/using-xamarin-android-i-want-to-sync-sqlite-with-sql-server" target="_blank" rel="noopener noreferrer">on StackOverflow</a>, in the official <a href="https://developer.xamarin.com/guides/xamarin-forms/cloud-services/sync/" target="_blank" rel="noopener noreferrer">Xamarin documentation</a> and on a lot of blogs, but its free plan seems to not be worth using (except of performing some simple tests) while paid plans are more <em>enterprisy</em>. It seems great, but for my playground I neither want to pay nor use free plan which may become unusable after re-implementing the whole back-end.</p>
<h4>Realm.io</h4>
<p>Finally, out of a sudden, I found it. <a href="https://realm.io/docs/get-started/overview/" target="_blank" rel="noopener noreferrer">Realm.io</a> is a totally separate database system built especially for mobile solutions. Its <a href="https://realm.io/products/realm-mobile-database/" target="_blank" rel="noopener noreferrer">Mobile Database</a> may be used as the db framework for a mobile app (<a href="https://realm.io/docs/xamarin/latest/" target="_blank" rel="noopener noreferrer">Xamarin is also supported</a>), replacing for instance <a href="https://www.codejourney.net/2017/03/using-sqlite-database-in-xamarin-android/" target="_blank" rel="noopener noreferrer">SQLite</a>. After all, <a href="https://realm.io/products/realm-mobile-platform/" target="_blank" rel="noopener noreferrer">Realm Mobile Platform</a> can be used on a server-side handling mobile/web APIs and data synchronization &#8211; documentation says it supports .NET Core 1.1. Let&#8217;s hope they add support for 2.0 soon.</p>
<p>What&#8217;s more it&#8217;s all open-source and provides <a href="https://realm.io/pricing/" target="_blank" rel="noopener noreferrer">really nice free plans</a>.</p>
<p>Realm.io looks very promising. I&#8217;m just a bit worried it&#8217;s almost never recommended on the web &#8211; is there something wrong with it? Maybe it&#8217;s a new stuff? Where&#8217;s a catch? Let me know if you&#8217;ve had any experience with it.</p>
<h4>SQLite-sync.com</h4>
<p>Last but maybe not least, I found <a href="http://sqlite-sync.com/" target="_blank" rel="noopener noreferrer">SQLite-sync.com</a>. The idea seems to be similar to Realm.io, however this product looks less mature. Not even 100 commits <a href="https://github.com/sqlite-sync/SQLite-sync.com/commits/master" target="_blank" rel="noopener noreferrer">on their GitHub</a> with just few contributors. Looking poor compared to <a href="https://github.com/realm/realm-dotnet" target="_blank" rel="noopener noreferrer">Realm.io&#8217;s GitHub</a> with more than 2.5k commits only for its .NET component.</p>
<p>The main (and the only?) benefit of using it would be the possibility to keep SQLite database in Xamarin.Android app. Apart from that, I don&#8217;t see any dominance over Realm.io.</p>
<h2>Summary</h2>
<p>As my research shows there are a lot of existing frameworks that help keeping data synchronized between mobile app and a remote back-end, allowing Xamarin app to work in offline-first approach. Microsoft offers great stuff in Azure, but in my opinion it&#8217;s not worth investing money for small <em>playground</em> apps.</p>
<p>For the moment I&#8217;m for Realm.io. It seems to provide very extended free plan, there&#8217;s a lot of resources on the web, folks talk about it on SO&#8230;</p>
<p>So now I&#8217;m asking you &#8211; <span style="text-decoration: underline;"><strong>do you have any experience with data sync in Xamarin apps? If yes, please share your insights and help me to choose the best approach <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></strong></span></p>
<p>I&#8217;d be grateful for any suggestions!</p>
<p>After the framework is chosen, I will try to design the whole synchronization system and share it with you here.</p></p>
<p>The post <a href="https://www.codejourney.net/xamarin-android-asp-net-web-api-synchronization-research/">Xamarin.Android &#8211; ASP.NET web api synchronization &#8211; research</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/xamarin-android-asp-net-web-api-synchronization-research/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2345</post-id>	</item>
		<item>
		<title>Managing Activity state changes using Bundle</title>
		<link>https://www.codejourney.net/managing-activity-state-changes-using-bundle/</link>
					<comments>https://www.codejourney.net/managing-activity-state-changes-using-bundle/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Mon, 29 May 2017 21:28:42 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[moneyback]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=2281</guid>

					<description><![CDATA[<p>Today we&#8217;re going to see how to manage (keep and restore) state of Activities in Xamarin.Android application in order to keep the app consistent and reactive for configuration/state changes. Why to keep and restore Activity&#8217;s state? As I already described in my post about Android Activities, the OS may react to some &#8220;constant&#8221; state changes&#8230;</p>
<p>The post <a href="https://www.codejourney.net/managing-activity-state-changes-using-bundle/">Managing Activity state changes using Bundle</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Today we&#8217;re going to see how to manage (keep and restore) state of <a href="https://www.codejourney.net/2017/03/xamarin-android-activities/" target="_blank" rel="noopener noreferrer">Activities</a> in Xamarin.Android application in order to keep the app consistent and reactive for configuration/state changes.<br />
<span id="more-2281"></span></p>
<h2>Why to keep and restore Activity&#8217;s state?</h2>
<p>As I already described in <a href="https://www.codejourney.net/2017/03/xamarin-android-activities/" target="_blank" rel="noopener noreferrer">my post about Android Activities</a>, the OS may react to some &#8220;constant&#8221; state changes by calling lifecycle methods during Activity&#8217;s life, which may be overridden by the programmer in order to take some additional actions. However, there are some behaviors in Android apps that may change its configuration, after which the state of the Activity (for instance: arrangement or some UI elements or checkboxes&#8217; selections) may be lost if not handled properly.</p>
<p>To give you a real example: in <em>MoneyBack</em> application there is a main screen with two tabs. I noticed that when the second tab is selected:</p>
<figure id="attachment_2282" aria-describedby="caption-attachment-2282" style="width: 229px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" fetchpriority="high" decoding="async" data-attachment-id="2282" data-permalink="https://www.codejourney.net/managing-activity-state-changes-using-bundle/moneyback_secondtab/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_SecondTab" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?fit=576%2C1024&amp;ssl=1" class="wp-image-2282" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?resize=229%2C406&#038;ssl=1" alt="" width="229" height="406" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?resize=720%2C1280&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?w=1080&amp;ssl=1 1080w" sizes="(max-width: 229px) 100vw, 229px" /></a><figcaption id="caption-attachment-2282" class="wp-caption-text"><em>MoneyBack</em> &#8211; 2nd tab selected</figcaption></figure>
<p>and the device is rotated:</p>
<figure id="attachment_2283" aria-describedby="caption-attachment-2283" style="width: 478px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" decoding="async" data-attachment-id="2283" data-permalink="https://www.codejourney.net/managing-activity-state-changes-using-bundle/moneyback_afterrotatefirsttab/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?fit=1920%2C1080&amp;ssl=1" data-orig-size="1920,1080" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_AfterRotateFirstTab" data-image-description="" data-image-caption="&lt;p&gt;MoneyBack &amp;#8211; 1st tab selected after rotating&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?fit=1024%2C576&amp;ssl=1" class="wp-image-2283" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?resize=478%2C269&#038;ssl=1" alt="" width="478" height="269" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?resize=300%2C169&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?resize=768%2C432&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?resize=1024%2C576&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?resize=720%2C405&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?w=1920&amp;ssl=1 1920w" sizes="(max-width: 478px) 100vw, 478px" /></a><figcaption id="caption-attachment-2283" class="wp-caption-text"><em>MoneyBack</em> &#8211; 1st tab selected after rotating</figcaption></figure>
<p><strong>first tab becomes selected</strong>. User is losing his input (selection of the 2nd tab).</p>
<p>Screen orientation change is one of the reasons why we should care about saving and restoring Activities&#8217; states.</p>
<h2>Keeping state changes &#8211; OnSaveInstanceState()</h2>
<p>Each Activity allows us to override <span style="color: #ff9900;">OnSaveInstanceState(<span style="color: #ff6600;">Bundle</span> outState)</span> method, which is called when the current Activity is to be killed (e.g. when device&#8217;s screen orientation is changing or the Activity needs to be killed by Android in order to release some resources).</p>
<p><strong>Please don&#8217;t confuse it with Activity Lifecycle Methods</strong> (which I already described <a href="https://www.codejourney.net/2017/03/xamarin-android-activities/" target="_blank" rel="noopener noreferrer">here</a>), like <span style="color: #ff9900;">OnPause()</span> or <span style="color: #ff9900;">OnStop()</span> which are always called by the OS when particular action occurs. <span style="color: #ff9900;">OnSaveInstanceState()</span> method is <strong>generally</strong> called after <span style="color: #ff9900;">OnPause()</span> and before <span style="color: #ff9900;">OnStop()</span>, but <strong>it&#8217;s not always the case</strong>. For instance, it won&#8217;t be called at all when user navigates back from <em>ActivityB</em> to <em>ActivityA</em>, as in this case <em>ActivityB</em> will never be killed. More details can be found in <a href="https://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState%28android.os.Bundle%29" target="_blank" rel="noopener noreferrer">official Android documentation</a>.</p>
<p><span style="color: #ff9900;">OnSaveInstanceState()</span> is called with <span style="color: #ff9900;">Bundle</span> parameter provided. It represents a simple key-value dictionary, which is additionally serialized, so it should be used for storing simple values like strings, integers etc. There are other structures and techniques for storing more complex data on state changes events (see the link in &#8220;Summary&#8221; section of this post).</p>
<p>In order to save currently selected tab, we can implement the method as follows:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist48172254" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-onsaveinstancestate-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="OnSaveInstanceState.cs content, created by dsibinski on 08:28PM on May 29, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="OnSaveInstanceState.cs">
<tr>
<td id="file-onsaveinstancestate-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-onsaveinstancestate-cs-LC1" class="blob-code blob-code-inner js-file-line">  protected override void OnSaveInstanceState(Bundle outState)</td>
</tr>
<tr>
<td id="file-onsaveinstancestate-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-onsaveinstancestate-cs-LC2" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-onsaveinstancestate-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-onsaveinstancestate-cs-LC3" class="blob-code blob-code-inner js-file-line">      var tabSelectedPosition = this.ActionBar.SelectedNavigationIndex;</td>
</tr>
<tr>
<td id="file-onsaveinstancestate-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-onsaveinstancestate-cs-LC4" class="blob-code blob-code-inner js-file-line">      outState.PutInt(&quot;selectedTabPosition&quot;, tabSelectedPosition);</td>
</tr>
<tr>
<td id="file-onsaveinstancestate-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-onsaveinstancestate-cs-LC5" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-onsaveinstancestate-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-onsaveinstancestate-cs-LC6" class="blob-code blob-code-inner js-file-line">      base.OnSaveInstanceState(outState);</td>
</tr>
<tr>
<td id="file-onsaveinstancestate-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-onsaveinstancestate-cs-LC7" class="blob-code blob-code-inner js-file-line">  }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/58260052f1fd8a7daffe99d4c63d634c/raw/1b9d19cc7369122ea997616b929899480521dc1e/OnSaveInstanceState.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/58260052f1fd8a7daffe99d4c63d634c#file-onsaveinstancestate-cs" class="Link--inTextBlock"><br />
          OnSaveInstanceState.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>Now, each screen orientation change will make this method called and the index of selected tab will be saved into <span style="color: #ff9900;">Bundle</span> <span style="color: #ff9900;">outState</span> dictionary under <em>&#8220;selectedTabPosition&#8221;</em> key.</p>
<h2>Restoring state changes &#8211; OnRestoreInstanceState()</h2>
<p>As soon as the Activity considered backs to life (is being resumed), <span style="color: #ff9900;">OnRestoreInstanceState(<span style="color: #ff6600;">Bundle</span> savedInstanceState)</span> method is called by the OS. <strong>It will only be called if there is a saved instance kept by calling <span style="color: #ff9900;">OnSaveInstanceState()</span> method before</strong>. As you can see, this method also comes with a <span style="color: #ff9900;">Bundle</span> parameter, which is the same key-value serialized dictionary we used for saving the Activity&#8217;s state.</p>
<p>In case of tabs selection restoring, we can implement this method as the following code presents:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist48172407" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-onrestoreinstancestate-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="OnRestoreInstanceState.cs content, created by dsibinski on 08:34PM on May 29, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="OnRestoreInstanceState.cs">
<tr>
<td id="file-onrestoreinstancestate-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-onrestoreinstancestate-cs-LC1" class="blob-code blob-code-inner js-file-line">  protected override void OnRestoreInstanceState(Bundle savedInstanceState)</td>
</tr>
<tr>
<td id="file-onrestoreinstancestate-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-onrestoreinstancestate-cs-LC2" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-onrestoreinstancestate-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-onrestoreinstancestate-cs-LC3" class="blob-code blob-code-inner js-file-line">      base.OnRestoreInstanceState(savedInstanceState);</td>
</tr>
<tr>
<td id="file-onrestoreinstancestate-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-onrestoreinstancestate-cs-LC4" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-onrestoreinstancestate-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-onrestoreinstancestate-cs-LC5" class="blob-code blob-code-inner js-file-line">      var previouslySelectedTabPosition = savedInstanceState.GetInt(&quot;selectedTabPosition&quot;, 0);</td>
</tr>
<tr>
<td id="file-onrestoreinstancestate-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-onrestoreinstancestate-cs-LC6" class="blob-code blob-code-inner js-file-line">      this.ActionBar.SetSelectedNavigationItem(previouslySelectedTabPosition);</td>
</tr>
<tr>
<td id="file-onrestoreinstancestate-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-onrestoreinstancestate-cs-LC7" class="blob-code blob-code-inner js-file-line">  }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/f620e7ae733cda6333cddd9abeced90c/raw/066fc7034dadbcfef47a358ec1c86bbb9a31b7f2/OnRestoreInstanceState.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/f620e7ae733cda6333cddd9abeced90c#file-onrestoreinstancestate-cs" class="Link--inTextBlock"><br />
          OnRestoreInstanceState.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p><span style="color: #ff9900;">previouslySelectedTabPosition </span>variable will be initialized with integer value from <span style="color: #ff9900;">Bundle</span> dictionary saved under <em>&#8220;selectedTabPosition&#8221;</em> key, or default value (<em>0</em>) if nothing saved for the key is found.</p>
<p><strong>NOTE</strong>: <span style="color: #ff9900;">Bundle</span> parameter provided in <span style="color: #ff9900;">OnRestoreInstanceState()</span> is exactly the same, as the one available in <span style="color: #ff9900;">OnCreate(<span style="color: #ff6600;">Bundle</span> bundle)</span> method called on Activity&#8217;s creation. We could actually also retrieve our saved value there, but in many cases restoring the state (like selecting previously selected tab) requires some UI elements to be already initialized, which should be handled within <span style="color: #ff9900;">OnCreate()</span> method before. Because of that, I&#8217;d rather suggest to restore Activity&#8217;s state using <span style="color: #ff9900;">OnRestoreInstanceState()</span> as a general rule (of course there may be some exceptional cases <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> ). <span style="color: #ff9900;">OnRestoreInstanceState()</span> will always be called <strong>after</strong> <span style="color: #ff9900;">OnCreate()</span>.</p>
<p>Moreover, if we wanted to use <span style="color: #ff9900;">Bundle</span> parameter in <span style="color: #ff9900;">OnCreate()</span> method, we&#8217;d need to check each time if <span style="color: #ff9900;">bundle</span> is not NULL (as we don&#8217;t know whether <span style="color: #ff9900;">OnSaveInstanceState()</span> had been called before).</p>
<p>As a result, the same tab as previously is selected even after rotating the device on <em>MoneyBack</em>&#8216;s <span style="color: #ff9900;">MainActivity</span>:</p>
<figure id="attachment_2287" aria-describedby="caption-attachment-2287" style="width: 826px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" decoding="async" data-attachment-id="2287" data-permalink="https://www.codejourney.net/managing-activity-state-changes-using-bundle/moneyback_rotate2-2/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?fit=4052%2C1968&amp;ssl=1" data-orig-size="4052,1968" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_rotate2" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?fit=1024%2C497&amp;ssl=1" class="wp-image-2287" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?resize=826%2C402&#038;ssl=1" alt="" width="826" height="402" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?resize=300%2C146&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?resize=768%2C373&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?resize=1024%2C497&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?resize=720%2C350&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?w=2280&amp;ssl=1 2280w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?w=3420&amp;ssl=1 3420w" sizes="(max-width: 826px) 100vw, 826px" /></a><figcaption id="caption-attachment-2287" class="wp-caption-text"><em>MoneyBack</em> &#8211; keeping tab selected when rotating</figcaption></figure>
<h2>&#8220;Automatic&#8221; state changes handled by Android OS</h2>
<p>Maybe you noticed in your Android application, that not every UI element needs to be handled &#8220;manually&#8221; by implementing the above-mentioned methods in order to save its state. Android performs some kind of &#8220;automatic&#8221; saving and restoration of basic UI elements&#8217; states.</p>
<p>The rule here is that as long as UI element (like <span style="color: #ff9900;">TextView</span> or <span style="color: #ff9900;">Button</span>) has its <span style="color: #ff9900;">android:id</span> set in <em>.axml</em> layout file, OS will automatically manage those elements&#8217; states (e.g. text entered into <span style="color: #ff9900;">EditText</span>).</p>
<p>For example, for <span style="color: #ff9900;">EditText</span> declared like that:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist48172903" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-edittext-axml" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-xml  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="EditText.axml content, created by dsibinski on 08:51PM on May 29, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="EditText.axml">
<tr>
<td id="file-edittext-axml-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-edittext-axml-LC1" class="blob-code blob-code-inner js-file-line">  &lt;EditText</td>
</tr>
<tr>
<td id="file-edittext-axml-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-edittext-axml-LC2" class="blob-code blob-code-inner js-file-line">  android:layout_width=&quot;match_parent&quot;</td>
</tr>
<tr>
<td id="file-edittext-axml-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-edittext-axml-LC3" class="blob-code blob-code-inner js-file-line">  android:layout_height=&quot;wrap_content&quot;</td>
</tr>
<tr>
<td id="file-edittext-axml-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-edittext-axml-LC4" class="blob-code blob-code-inner js-file-line">  android:id=&quot;@+id/inputEventName&quot;</td>
</tr>
<tr>
<td id="file-edittext-axml-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-edittext-axml-LC5" class="blob-code blob-code-inner js-file-line">  android:fadingEdge=&quot;none&quot; /&gt;</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/0b3920ba34d87ac7b8d70bab199dd430/raw/c41dc4d096994c0be50c064a2f3331c7e7a710d3/EditText.axml" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/0b3920ba34d87ac7b8d70bab199dd430#file-edittext-axml" class="Link--inTextBlock"><br />
          EditText.axml<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>its properties (especially its <strong>Text</strong> property) will be automatically saved and restored on screen orientation changes.</p>
<h2>Summary</h2>
<p>We&#8217;ve seen how to handle Android Activities&#8217; state changes caused by configuration modification (e.g. screen orientation change, Activity being killed by the OS in order to free some resources etc.) by implementing <span style="color: #ff9900;">OnSaveInstanceState()</span> and <span style="color: #ff9900;">OnRestoreInstanceState()</span>, where we added and retrieved key-value data to/from <span style="color: #ff9900;">Bundle</span> serialized dictionary. We just need to remember that those methods are not always called (e.g. when navigating between Activities using &#8220;back&#8221; button), so these should be used only for certain kind of state changes.</p>
<p>We&#8217;ve also seen that UI controls with their <span style="color: #ff9900;">android:id</span> defined in layout files have their states <em>resistant</em> for configuration changes (handled automatically by Android OS).</p>
<p><span style="color: #ff9900;">Bundle</span> dictionary is serialized for better performance and memory utilization, so only simple-typed values should be stored in it (like strings or integers). In order to store more complex data, Android provides different possibilities of managing it (e.g. using <a href="https://developer.android.com/reference/android/app/Activity.html#onRetainNonConfigurationInstance()" target="_blank" rel="noopener noreferrer">OnRetainNonConfigurationInstance</a>).</p>
<p>The post <a href="https://www.codejourney.net/managing-activity-state-changes-using-bundle/">Managing Activity state changes using Bundle</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/managing-activity-state-changes-using-bundle/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2281</post-id>	</item>
		<item>
		<title>Date selection using DatePickerDialog in Xamarin.Android</title>
		<link>https://www.codejourney.net/date-selection-using-datepickerdialog-in-xamarin-android/</link>
					<comments>https://www.codejourney.net/date-selection-using-datepickerdialog-in-xamarin-android/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Sat, 27 May 2017 13:19:47 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[moneyback]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=2266</guid>

					<description><![CDATA[<p>In this post, we&#8217;re going to see how to provide a nice Android UI control for selecting the date using DatePickerDialog. The dialog looks as follows: It may be opened e.g. when clicking on a button in the app, as I used it in MoneyBack. Creating DatePickerFragment First of all, we will implement the dialog to be displayed&#8230;</p>
<p>The post <a href="https://www.codejourney.net/date-selection-using-datepickerdialog-in-xamarin-android/">Date selection using DatePickerDialog in Xamarin.Android</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this post, we&#8217;re going to see how to provide a nice Android UI control for selecting the date using <span style="color: #ff9900;">DatePickerDialog</span>.<br />
<span id="more-2266"></span></p>
<p>The dialog looks as follows:</p>
<figure id="attachment_2267" aria-describedby="caption-attachment-2267" style="width: 238px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2267" data-permalink="https://www.codejourney.net/date-selection-using-datepickerdialog-in-xamarin-android/event_datepicker/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Event_DatePicker" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?fit=576%2C1024&amp;ssl=1" class="wp-image-2267 " src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?resize=238%2C423&#038;ssl=1" alt="" width="238" height="423" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?resize=720%2C1280&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?w=1080&amp;ssl=1 1080w" sizes="auto, (max-width: 238px) 100vw, 238px" /></a><figcaption id="caption-attachment-2267" class="wp-caption-text">DatePickerDialog</figcaption></figure>
<p>It may be opened e.g. when clicking on a button in the app, as I used it in <em>MoneyBack</em>.</p>
<h2>Creating DatePickerFragment</h2>
<p>First of all, we will implement the dialog to be displayed within <span style="color: #ff6600;">DialogFragment.</span> Doing that our dialog will be able to be displayed as independent piece of UI on the top of any Activity.</p>
<p>The second requirement is to implement <span style="color: #ff6600;">IOnDateSetListener</span> interface (coming from Java/Android), which provides a callback on date selection action done by the user.</p>
<p>The <span style="color: #ff6600;">DatePickerFragment</span> meeting those two requirements may look as follows:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist48103396" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-datepickerfragment-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="DatePickerFragment.cs content, created by dsibinski on 12:35PM on May 27, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="DatePickerFragment.cs">
<tr>
<td id="file-datepickerfragment-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-datepickerfragment-cs-LC1" class="blob-code blob-code-inner js-file-line">  public class DatePickerFragment : DialogFragment, DatePickerDialog.IOnDateSetListener</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-datepickerfragment-cs-LC2" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-datepickerfragment-cs-LC3" class="blob-code blob-code-inner js-file-line">      public static readonly string TAG = &quot;X:&quot; + typeof(DatePickerFragment).Name.ToUpper();</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-datepickerfragment-cs-LC4" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-datepickerfragment-cs-LC5" class="blob-code blob-code-inner js-file-line">      Action&lt;DateTime&gt; _dateSelectedHandler = delegate { };</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-datepickerfragment-cs-LC6" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-datepickerfragment-cs-LC7" class="blob-code blob-code-inner js-file-line">      public DatePickerFragment(Action&lt;DateTime&gt; onDateSelected)</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-datepickerfragment-cs-LC8" class="blob-code blob-code-inner js-file-line">      {</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-datepickerfragment-cs-LC9" class="blob-code blob-code-inner js-file-line">          _dateSelectedHandler = onDateSelected;</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-datepickerfragment-cs-LC10" class="blob-code blob-code-inner js-file-line">      }</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-datepickerfragment-cs-LC11" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-datepickerfragment-cs-LC12" class="blob-code blob-code-inner js-file-line">      public override Dialog OnCreateDialog(Bundle savedInstanceState)</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-datepickerfragment-cs-LC13" class="blob-code blob-code-inner js-file-line">      {</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-datepickerfragment-cs-LC14" class="blob-code blob-code-inner js-file-line">          DateTime now = DateTime.Now;</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-datepickerfragment-cs-LC15" class="blob-code blob-code-inner js-file-line">          return new DatePickerDialog(Activity, </td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-datepickerfragment-cs-LC16" class="blob-code blob-code-inner js-file-line">              this,</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-datepickerfragment-cs-LC17" class="blob-code blob-code-inner js-file-line">              now.Year,</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-datepickerfragment-cs-LC18" class="blob-code blob-code-inner js-file-line">              now.Month,</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
<td id="file-datepickerfragment-cs-LC19" class="blob-code blob-code-inner js-file-line">              now.Day);</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L20" class="blob-num js-line-number js-blob-rnum" data-line-number="20"></td>
<td id="file-datepickerfragment-cs-LC20" class="blob-code blob-code-inner js-file-line">      }</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L21" class="blob-num js-line-number js-blob-rnum" data-line-number="21"></td>
<td id="file-datepickerfragment-cs-LC21" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L22" class="blob-num js-line-number js-blob-rnum" data-line-number="22"></td>
<td id="file-datepickerfragment-cs-LC22" class="blob-code blob-code-inner js-file-line">      public void OnDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L23" class="blob-num js-line-number js-blob-rnum" data-line-number="23"></td>
<td id="file-datepickerfragment-cs-LC23" class="blob-code blob-code-inner js-file-line">      {</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L24" class="blob-num js-line-number js-blob-rnum" data-line-number="24"></td>
<td id="file-datepickerfragment-cs-LC24" class="blob-code blob-code-inner js-file-line">          DateTime selectedDate = new DateTime(year, monthOfYear + 1, dayOfMonth);</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L25" class="blob-num js-line-number js-blob-rnum" data-line-number="25"></td>
<td id="file-datepickerfragment-cs-LC25" class="blob-code blob-code-inner js-file-line">          _dateSelectedHandler(selectedDate);</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L26" class="blob-num js-line-number js-blob-rnum" data-line-number="26"></td>
<td id="file-datepickerfragment-cs-LC26" class="blob-code blob-code-inner js-file-line">      }</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L27" class="blob-num js-line-number js-blob-rnum" data-line-number="27"></td>
<td id="file-datepickerfragment-cs-LC27" class="blob-code blob-code-inner js-file-line">  }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/6bddb5f760a83b1d190d7d20362f1546/raw/eb5d54ac22e31860c2925eaa58ec078d545d43d2/DatePickerFragment.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/6bddb5f760a83b1d190d7d20362f1546#file-datepickerfragment-cs" class="Link--inTextBlock"><br />
          DatePickerFragment.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>There are few crucial parts in above-listed class:</p>
<ul>
<li>Line 1: as said before, the class derives from <span style="color: #ff6600;">DialogFragment</span> and implements <span style="color: #ff6600;">IOnDateSetListener</span> interface</li>
<li>Line 3: here we have <span style="color: #ff6600;">public static readonly string TAG</span> variable defined &#8211; it is used as a unique identifier of the <span style="color: #ff6600;">Fragment</span>; in some cases, <span style="color: #ff6600;">Fragments</span> can be displayed without any UI &#8211; in such case the only possibility to identify and get the <span style="color: #ff6600;">Fragment</span> is by using <a href="https://developer.android.com/reference/android/app/FragmentManager.html#findFragmentByTag(java.lang.String)" target="_blank" rel="noopener noreferrer">findFragmentByTag()</a> method</li>
<li>Lines 5-10: define <span style="color: #ff6600;">_dateSelectedHandler</span> delegate which may be provided to the constructor of our <span style="color: #ff6600;">DatePickerFragment</span> with the method to be called-back when user selects a date</li>
<li>Lines 12-20: inheriting from <span style="color: #ff6600;">DialogFragment</span> allows us to override its <a href="https://developer.android.com/reference/android/app/DialogFragment.html#Lifecycle" target="_blank" rel="noopener noreferrer">lifecycle methods</a> &#8211; one of them is <span style="color: #ff6600;">Dialog <span style="color: #993300;">OnCreateDialog</span>(Bundle <span style="color: #993300;">savedInstanceState</span>)</span>, in which we actually create the <span style="color: #ff6600;">Dialog</span>-inheriting class &#8211; in our case &#8211; <span style="color: #ff6600;">DatePickerDialog</span> &#8211; with initially selected date (set to current date in the provided example)</li>
<li>Lines 22-26: implementing <span style="color: #ff9900;">IOnDateSetListener </span>interface requires to implement <span style="color: #ff9900;">OnDateSet</span> method, which is called when the user selects the date and clicks &#8220;OK&#8221; button;<b><br />
NOTE</b>: one of this method&#8217;s arguments is <span style="color: #ff9900;">monthOfYear</span> integer value, which contains month number expressed as values 0-11 (NOT 1-12) for compatibility with <a href="https://developer.android.com/reference/java/util/Calendar.html#MONTH" target="_blank" rel="noopener noreferrer">java.util.Calendar.MONTH</a></li>
</ul>
<h2>Using DatePickerFragment</h2>
<p>In <em>MoneyBack</em> application I&#8217;ve used <span style="color: #ff9900;">DatePickerFragment</span> on creating/modifying an event, when user needs to select its date:</p>
<figure id="attachment_2275" aria-describedby="caption-attachment-2275" style="width: 223px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2275" data-permalink="https://www.codejourney.net/date-selection-using-datepickerdialog-in-xamarin-android/event_dateselection/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Event_DateSelection" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?fit=576%2C1024&amp;ssl=1" class="wp-image-2275" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?resize=223%2C396&#038;ssl=1" alt="" width="223" height="396" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?resize=720%2C1280&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?w=1080&amp;ssl=1 1080w" sizes="auto, (max-width: 223px) 100vw, 223px" /></a><figcaption id="caption-attachment-2275" class="wp-caption-text"><em>MoneyBack</em> &#8211; event&#8217;s date selection</figcaption></figure>
<p>As soon as the button is clicked, the following code executes:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist48103872" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-eventdetailsactivity_dateclick-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="EventDetailsActivity_DateClick.cs content, created by dsibinski on 12:57PM on May 27, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="EventDetailsActivity_DateClick.cs">
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC1" class="blob-code blob-code-inner js-file-line">  private void _btnSelectDate_Click(object sender, EventArgs e)</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC2" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC3" class="blob-code blob-code-inner js-file-line">      new DatePickerFragment(delegate(DateTime time)</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC4" class="blob-code blob-code-inner js-file-line">          {</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC5" class="blob-code blob-code-inner js-file-line">              _selectedDate = time;</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC6" class="blob-code blob-code-inner js-file-line">              _btnSelectDate.Text = _selectedDate.ToLongDateString();</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC7" class="blob-code blob-code-inner js-file-line">          })</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC8" class="blob-code blob-code-inner js-file-line">          .Show(FragmentManager, DatePickerFragment.TAG);</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC9" class="blob-code blob-code-inner js-file-line">  }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/930a05f6a51752d773651941b1dd5135/raw/4ef6b702c3c5ee9580a66ee6aef6310772856ad7/EventDetailsActivity_DateClick.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/930a05f6a51752d773651941b1dd5135#file-eventdetailsactivity_dateclick-cs" class="Link--inTextBlock"><br />
          EventDetailsActivity_DateClick.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>As you can see, to <span style="color: #ff9900;">DatePickerFragment</span>&#8216;s constructor I&#8217;m providing the delegate with a method to be called when the date is selected by the user (setting <span style="color: #ff9900;">_selectedDate</span> property with selected <span style="color: #ff9900;">time</span> and putting the date in short format as button&#8217;s <span style="color: #ff9900;">Text</span>).</p>
<p>In order to display a dialog, <a href="https://developer.android.com/reference/android/app/DialogFragment.html#show(android.app.FragmentManager, java.lang.String)" target="_blank" rel="noopener noreferrer">Show</a> method is called, taking current <span style="color: #ff9900;">FragmentManager</span> and already mentioned per-Fragment-unique <span style="color: #ff9900;">tag string</span>, defined statically in <span style="color: #ff9900;">DatePickerFragment</span> class.</p>
<h2>Summary</h2>
<p>Today&#8217;s short post presented how to easily create a <span style="color: #ff9900;">DialogFragment</span> showing <span style="color: #ff9900;">DatePickerDialog</span> for date selection, which allows to provide any method to be called-back when the date is selected by the user.</p>
<p>I hope you&#8217;ll find it useful <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>The post <a href="https://www.codejourney.net/date-selection-using-datepickerdialog-in-xamarin-android/">Date selection using DatePickerDialog in Xamarin.Android</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/date-selection-using-datepickerdialog-in-xamarin-android/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2266</post-id>	</item>
		<item>
		<title>MoneyBack &#8211; 3 weeks before the end of DSP</title>
		<link>https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/</link>
					<comments>https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Tue, 09 May 2017 22:09:45 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[moneyback]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=2192</guid>

					<description><![CDATA[<p>In today&#8217;s post I&#8217;d like to present what&#8217;s the current status of works on MoneyBack application, 3 weeks before the end of DSP competition. In general, the project hasn&#8217;t been going as well as I expected and is currently not as advanced as I&#8217;d expect it to be at this stage. There are many reasons behind that,&#8230;</p>
<p>The post <a href="https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/">MoneyBack &#8211; 3 weeks before the end of DSP</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In today&#8217;s post I&#8217;d like to present what&#8217;s the current status of works on <em>MoneyBack</em> application, 3 weeks before the end of DSP competition.<br />
<span id="more-2192"></span></p>
<p>In general, the project hasn&#8217;t been going as well as I expected and is currently not as advanced as I&#8217;d expect it to be at this stage. There are many reasons behind that, including lack of time recently and many issues met during development, however, as I already wrote in my <a href="https://www.codejourney.net/2017/02/hello-dajsiepoznac2017/" target="_blank" rel="noopener noreferrer">DSP introducing post</a>, the most important is to survive with the project to the end of the competition and meet all requirements. <span style="text-decoration: underline;">The end of DSP doesn&#8217;t equal the end of <em>MoneyBack</em></span> <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>That&#8217;s why in this post I&#8217;d like to show you how the project looks currently and what&#8217;s still to be done. Moreover, as <a href="https://www.codejourney.net/2017/03/using-sqlite-database-in-xamarin-android/" target="_blank" rel="noopener noreferrer">I promised before</a>, <strong>I&#8217;m publishing <a href="https://trello.com/b/pD6NLfH4" target="_blank" rel="noopener noreferrer">my Trello board</a> with tasks still to be done within the project.</strong></p>
<h2>UI changes</h2>
<p>For the last days working on the project I&#8217;ve been trying to make the UI of <em>MoneyBack</em> some kind of &#8220;final&#8221; version, so I can easily extend it adding new functionalities and focus on development instead of spending time on interface design, which is not important for me at the moment. I met many issues with that, which I think came from using some deprecated UI elements I used (e.g. <a href="https://developer.xamarin.com/guides/android/user_interface/working_with_listviews_and_adapters/" target="_blank" rel="noopener noreferrer">ListView and Adapters</a>) that are not fully-supported in the newest versions of Android. Tutorials are also not really up-to-date for those components. Maybe that&#8217;s also because when I wanted to implement displaying a list of entities I looked in Google for something like &#8220;xamarin android list of elements&#8221; which lead me to this <a href="https://developer.xamarin.com/guides/android/user_interface/working_with_listviews_and_adapters/" target="_blank" rel="noopener noreferrer">ListView and Adapters</a> tutorial. Instead of firstly reading the whole User Interface tutorial, I wanted to implement displaying the list quickly, so I used those deprecated elements instead of implementing for instance newer and recommended <a href="https://developer.xamarin.com/guides/android/user_interface/recyclerview/" target="_blank" rel="noopener noreferrer">RecyclerView</a> from the beginning, which would be easier extensible now. That definitely teaches me that <strong>I should get to know a particular topic/area better and wider before deciding to use one of the possible solutions to solve a problem</strong>. Sometimes we want to implement something particular quickly, but later it produces more issues than benefits.</p>
<p>Finally I <a href="https://github.com/dsibinski/MoneyBack/commit/db3594f47d10ea543d9a9d2d4869097455590626" target="_blank" rel="noopener noreferrer">added tabs</a> (only one tab for People for now, but it will be easy to add new ones now) and <a href="https://github.com/dsibinski/MoneyBack/commit/386df7738060d8871cca65830ed5ef186ca9e62f" target="_blank" rel="noopener noreferrer">ActionBar menu</a> on the main Activity of the app:</p>
<figure id="attachment_2204" aria-describedby="caption-attachment-2204" style="width: 169px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2204" data-permalink="https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/moneyback_mainwithtabs/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_MainWithTabs" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?fit=576%2C1024&amp;ssl=1" class="wp-image-2204 size-medium" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?resize=169%2C300&#038;ssl=1" alt="" width="169" height="300" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?resize=720%2C1280&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?w=1080&amp;ssl=1 1080w" sizes="auto, (max-width: 169px) 100vw, 169px" /></a><figcaption id="caption-attachment-2204" class="wp-caption-text">MoneyBack &#8211; tabs</figcaption></figure>
<p>On the screenshot above, in the right-upper corner there is &#8220;Add&#8221; button visible when clicking on ActionBar menu. It opens a new person&#8217;s adding screen, on which I made name and email fields mandatory:</p>
<figure id="attachment_2205" aria-describedby="caption-attachment-2205" style="width: 169px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2205" data-permalink="https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/moneyback_personadding/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_PersonAdding" data-image-description="" data-image-caption="&lt;p&gt;MoneyBack &amp;#8211; adding Person&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?fit=576%2C1024&amp;ssl=1" class="size-medium wp-image-2205" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?resize=169%2C300&#038;ssl=1" alt="" width="169" height="300" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?resize=720%2C1280&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?w=1080&amp;ssl=1 1080w" sizes="auto, (max-width: 169px) 100vw, 169px" /></a><figcaption id="caption-attachment-2205" class="wp-caption-text">MoneyBack &#8211; adding Person</figcaption></figure>
<p>People added are then displayed on the main screen of the app in &#8220;People&#8221; tab:</p>
<figure id="attachment_2206" aria-describedby="caption-attachment-2206" style="width: 169px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2206" data-permalink="https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/moneyback_list/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_List" data-image-description="" data-image-caption="&lt;p&gt;MoneyBack &amp;#8211; list of people&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?fit=576%2C1024&amp;ssl=1" class="size-medium wp-image-2206" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?resize=169%2C300&#038;ssl=1" alt="" width="169" height="300" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?resize=720%2C1280&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?w=1080&amp;ssl=1 1080w" sizes="auto, (max-width: 169px) 100vw, 169px" /></a><figcaption id="caption-attachment-2206" class="wp-caption-text">MoneyBack &#8211; list of people</figcaption></figure>
<h2>Code &#8211; interesting parts</h2>
<h5>Using tabs layout in an Activity</h5>
<p>It turned out that using tabs-like layout in the Activity is pretty easy. In the AXML layout file for <span style="color: #ff9900;">MainActivity</span> I just added a <span style="color: #ff9900;">FrameLayout</span> container, within which the tabs and their contents are to be displayed:</p>
<style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47515921" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-main-axml" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-xml  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="Main.axml content, created by dsibinski on 09:21PM on May 09, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="Main.axml">
<tr>
<td id="file-main-axml-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-main-axml-LC1" class="blob-code blob-code-inner js-file-line">&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-main-axml-LC2" class="blob-code blob-code-inner js-file-line">    android:orientation=&quot;vertical&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-main-axml-LC3" class="blob-code blob-code-inner js-file-line">    android:layout_width=&quot;match_parent&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-main-axml-LC4" class="blob-code blob-code-inner js-file-line">    android:layout_height=&quot;match_parent&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-main-axml-LC5" class="blob-code blob-code-inner js-file-line">    android:minWidth=&quot;25px&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-main-axml-LC6" class="blob-code blob-code-inner js-file-line">    android:minHeight=&quot;25px&quot;&gt;</td>
</tr>
<tr>
<td id="file-main-axml-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-main-axml-LC7" class="blob-code blob-code-inner js-file-line">    &lt;FrameLayout</td>
</tr>
<tr>
<td id="file-main-axml-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-main-axml-LC8" class="blob-code blob-code-inner js-file-line">        android:minWidth=&quot;25px&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-main-axml-LC9" class="blob-code blob-code-inner js-file-line">        android:minHeight=&quot;25px&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-main-axml-LC10" class="blob-code blob-code-inner js-file-line">        android:layout_width=&quot;match_parent&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-main-axml-LC11" class="blob-code blob-code-inner js-file-line">        android:layout_height=&quot;match_parent&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-main-axml-LC12" class="blob-code blob-code-inner js-file-line">        android:id=&quot;@+id/tabFragmentsContainer&quot; /&gt;</td>
</tr>
<tr>
<td id="file-main-axml-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-main-axml-LC13" class="blob-code blob-code-inner js-file-line">&lt;/LinearLayout&gt;</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/8871cef3404f1b82834a46b2512c9263/raw/c5d3c8472e50d3f0b4e49921613b6b9abea954e0/Main.axml" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/8871cef3404f1b82834a46b2512c9263#file-main-axml" class="Link--inTextBlock"><br />
          Main.axml<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>I called it <span style="color: #ff9900;">tabFragmentsContainer</span>, because within each tab we will display a <span style="color: #000000;"><em>Fragment</em>. <em>Fragment</em> </span>represents a part of UI and/or behavior, which is displayed within an Activity. You can think of Fragments as smaller pieces, that can be placed onto (inside) Activities.</p>
<p>Basically, I changed <span style="color: #ff9900;">PeopleListActivity</span> to <span style="color: #ff9900;">PeopleListFragment</span>, which in fact only required changing inheritance from being a child of <span style="color: #ff9900;">Activity</span> to inheriting from <span style="color: #ff9900;">ListFragment</span> (which is a special kind of <span style="color: #ff9900;">Fragment</span> used for displaying lists of elements). The complete code of <span style="color: #ff9900;">PeopleListFragment</span> can be found <a href="https://gist.github.com/dsibinski/a90e6c8d63e5226dd9c2d3bb1f94db61" target="_blank" rel="noopener noreferrer">in this public Gist</a>.</p>
<p>In the end, making <span style="color: #ff9900;">MainActivity</span> displaying tabs requires setting its ActionBar&#8217;s navigation mode to <span style="color: #ff9900;">ActionBarNavigationMode.Tabs</span>:</p>
<pre><pre class="brush: csharp; title: ; notranslate">this.ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;</pre>
<p>and adding as many tabs as you wish, using for instance code similar to the following one:</p>
<style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47516212" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-mainactivity_addtab-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="MainActivity_AddTab.cs content, created by dsibinski on 09:31PM on May 09, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="MainActivity_AddTab.cs">
<tr>
<td id="file-mainactivity_addtab-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-mainactivity_addtab-cs-LC1" class="blob-code blob-code-inner js-file-line">void AddTab(string tabText, Fragment view)</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-mainactivity_addtab-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-mainactivity_addtab-cs-LC3" class="blob-code blob-code-inner js-file-line">    var tab = this.ActionBar.NewTab();</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-mainactivity_addtab-cs-LC4" class="blob-code blob-code-inner js-file-line">    tab.SetText(tabText);</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-mainactivity_addtab-cs-LC5" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-mainactivity_addtab-cs-LC6" class="blob-code blob-code-inner js-file-line">    tab.TabSelected += delegate (object sender, ActionBar.TabEventArgs e)</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-mainactivity_addtab-cs-LC7" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-mainactivity_addtab-cs-LC8" class="blob-code blob-code-inner js-file-line">        var fragment = this.FragmentManager.FindFragmentById(Resource.Id.tabFragmentsContainer);</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-mainactivity_addtab-cs-LC9" class="blob-code blob-code-inner js-file-line">        if (fragment != null)</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-mainactivity_addtab-cs-LC10" class="blob-code blob-code-inner js-file-line">            e.FragmentTransaction.Remove(fragment);</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-mainactivity_addtab-cs-LC11" class="blob-code blob-code-inner js-file-line">        e.FragmentTransaction.Add(Resource.Id.tabFragmentsContainer, view);</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-mainactivity_addtab-cs-LC12" class="blob-code blob-code-inner js-file-line">    };</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-mainactivity_addtab-cs-LC13" class="blob-code blob-code-inner js-file-line">    tab.TabUnselected += delegate (object sender, ActionBar.TabEventArgs e) {</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-mainactivity_addtab-cs-LC14" class="blob-code blob-code-inner js-file-line">        e.FragmentTransaction.Remove(view);</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-mainactivity_addtab-cs-LC15" class="blob-code blob-code-inner js-file-line">    };</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-mainactivity_addtab-cs-LC16" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-mainactivity_addtab-cs-LC17" class="blob-code blob-code-inner js-file-line">    this.ActionBar.AddTab(tab);</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-mainactivity_addtab-cs-LC18" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/621414dcb86e331e87b0ffd12939df1b/raw/36117bd3f8c95db8bba1e8a493ef5835292afbd5/MainActivity_AddTab.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/621414dcb86e331e87b0ffd12939df1b#file-mainactivity_addtab-cs" class="Link--inTextBlock"><br />
          MainActivity_AddTab.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>The arguments are name of the tab and an instance of a <span style="color: #ff9900;">Fragment</span> we want to have displayed in this tab (<span style="color: #ff9900;">PeopleListFragment<span style="color: #000000;">&#8216;s</span></span> instance in our case).</p>
<p>Lines 6-12 present what happens when the tab is selected by the user &#8211; <span style="color: #ff9900;">Fragment</span>&#8216;s instance is added to previously defined <span style="color: #ff9900;">tabFragmentsContainer</span>.</p>
<p>Lines 13-15 define callback method on tab deselection &#8211; <span style="color: #ff9900;">Fragment</span> is removed from the container.</p>
<h5>Adding ActionBar with menu to the Activity</h5>
<p>Addition of ActionBar with menu button in right-upper corner of the Activity requires creating an XML view in Resources/menu folder first (with one button in our case):</p>
<style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47516362" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-actionbarmenu-xml" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-xml  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="ActionBarMenu.xml content, created by dsibinski on 09:37PM on May 09, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="ActionBarMenu.xml">
<tr>
<td id="file-actionbarmenu-xml-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-actionbarmenu-xml-LC1" class="blob-code blob-code-inner js-file-line">&lt;menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;</td>
</tr>
<tr>
<td id="file-actionbarmenu-xml-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-actionbarmenu-xml-LC2" class="blob-code blob-code-inner js-file-line">  &lt;item android:id=&quot;@+id/menuAdd&quot;</td>
</tr>
<tr>
<td id="file-actionbarmenu-xml-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-actionbarmenu-xml-LC3" class="blob-code blob-code-inner js-file-line">        android:title=&quot;@string/menuAddTitle&quot;/&gt;</td>
</tr>
<tr>
<td id="file-actionbarmenu-xml-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-actionbarmenu-xml-LC4" class="blob-code blob-code-inner js-file-line">&lt;/menu&gt;</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/5bf6c6753228cbe52b38e4aba429cacb/raw/3d4dafa8cc94ab3f754787097609cd81b4e30e4a/ActionBarMenu.xml" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/5bf6c6753228cbe52b38e4aba429cacb#file-actionbarmenu-xml" class="Link--inTextBlock"><br />
          ActionBarMenu.xml<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>and then in the Activity considered overriding <span style="color: #ff9900;">OnCreateOptionsMenu</span> method inflating ActionBar&#8217;s menu using created view:</p>
<style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47516393" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-mainactivity_oncreateoptionsmenu-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="MainActivity_OnCreateOptionsMenu.cs content, created by dsibinski on 09:39PM on May 09, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="MainActivity_OnCreateOptionsMenu.cs">
<tr>
<td id="file-mainactivity_oncreateoptionsmenu-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-mainactivity_oncreateoptionsmenu-cs-LC1" class="blob-code blob-code-inner js-file-line">public override bool OnCreateOptionsMenu(IMenu menu)</td>
</tr>
<tr>
<td id="file-mainactivity_oncreateoptionsmenu-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-mainactivity_oncreateoptionsmenu-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-mainactivity_oncreateoptionsmenu-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-mainactivity_oncreateoptionsmenu-cs-LC3" class="blob-code blob-code-inner js-file-line">    MenuInflater.Inflate(Resource.Menu.ActionBarMenu, menu);</td>
</tr>
<tr>
<td id="file-mainactivity_oncreateoptionsmenu-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-mainactivity_oncreateoptionsmenu-cs-LC4" class="blob-code blob-code-inner js-file-line">    return base.OnPrepareOptionsMenu(menu);</td>
</tr>
<tr>
<td id="file-mainactivity_oncreateoptionsmenu-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-mainactivity_oncreateoptionsmenu-cs-LC5" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/4053bd9d9aaf8d28fbf6960b1a5855df/raw/7e6a1422dfa2eccbd8936ff28bbdf0ee4ea6ec99/MainActivity_OnCreateOptionsMenu.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/4053bd9d9aaf8d28fbf6960b1a5855df#file-mainactivity_oncreateoptionsmenu-cs" class="Link--inTextBlock"><br />
          MainActivity_OnCreateOptionsMenu.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>We also need to define what happens when a menu option is selected. For that purpose, override <span style="color: #ff9900;">OnOptionsItemSelected</span> method:</p>
<style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47516427" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-mainactivity_onoptionsitemselected-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="MainActivity_OnOptionsItemSelected.cs content, created by dsibinski on 09:40PM on May 09, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="MainActivity_OnOptionsItemSelected.cs">
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC1" class="blob-code blob-code-inner js-file-line">public override bool OnOptionsItemSelected(IMenuItem item)</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC3" class="blob-code blob-code-inner js-file-line">    if (item.ItemId == Resource.Id.menuAdd)</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC4" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC5" class="blob-code blob-code-inner js-file-line">        OpenAddingNewPerson();</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC6" class="blob-code blob-code-inner js-file-line">        return true;</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC7" class="blob-code blob-code-inner js-file-line">    }</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC8" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC9" class="blob-code blob-code-inner js-file-line">    return base.OnOptionsItemSelected(item);</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC10" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/80803c442ea4c4027bc5db86b7a528da/raw/9d380aa4d43cf8d20a6d47ca8323d2e147d7423a/MainActivity_OnOptionsItemSelected.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/80803c442ea4c4027bc5db86b7a528da#file-mainactivity_onoptionsitemselected-cs" class="Link--inTextBlock"><br />
          MainActivity_OnOptionsItemSelected.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<h2>Next coding tasks</h2>
<p>From now on you can watch <a href="https://trello.com/b/pD6NLfH4" target="_blank" rel="noopener noreferrer">my public Trello board</a>, where I have all tasks to be done in the nearest future in <em>MoneyBack</em> defined. I will try to define deadlines for those tasks as well.</p>
<p>At the moment of writing this post, <a href="https://github.com/dsibinski/MoneyBack/commit/d6f58805dc8f9e8c0b303cf8ecbfd3bbf4930aff" target="_blank" rel="noopener noreferrer">I&#8217;ve started adding a possibility to create Events</a>. I will need to keep many-to-many relationship between Person and Event entities and I will probably use <a href="https://bitbucket.org/twincoders/sqlite-net-extensions" target="_blank" rel="noopener noreferrer">SQLite-Net Extensions</a> library for that. You can expect a separate post about defining relationships using this library soon <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h2>Other tasks left to be done</h2>
<p>Apart from coding and developing the project, I still need to fulfill the <a href="https://www.codejourney.net/2017/02/hello-dajsiepoznac2017/" target="_blank" rel="noopener noreferrer">DSP competition&#8217;s requirements</a>. This is my 14th post within <a href="https://www.codejourney.net/category/dajsiepoznac2017/" target="_blank" rel="noopener noreferrer">DajSiePoznac2017</a>, so 6 posts still to be written. I have the ideas in my mind already and few next posts planned. There are only 3 weeks left to the end of the competition, so those days will need to be more intensive that it recently was, but that&#8217;s good, it means that you should be receiving more content here in the coming days and I will be spending more time on developing <em>MoneyBack</em>. Only positive changes, I hope <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h2>Summary</h2>
<p>We saw the status of <em>MoneyBack</em> project today. There are still many things to be done in the app to at least fulfill the minimal requirements I assumed in the beginning of the competition. but as I mentioned, the end of DSP is not the end of <em>MoneyBack</em> <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> On the other hand, DSP is a very good motivator, so I&#8217;ll try to make coming days and weeks more intensive. The most important goal for now is to fulfill the competition&#8217;s requirements for having 20 posts written until the end of May, which shouldn&#8217;t be problematic at all <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>I&#8217;ve also published my Trello dashboard. You can find a link to it <a href="https://www.codejourney.net/dajsiepoznac-2017/" target="_blank" rel="noopener noreferrer">here</a>.</p>
<p>Using this opportunity, I&#8217;d like to wish all DSP&#8217;17 participants good luck in the last weeks of the competition. I&#8217;m constantly reading the others&#8217; blogs and I see a lot of very nice and decent quality stuff appearing in Polish programming community on your blogs and repositories &#8211; great job!</p>
<p>Keep your fingers crossed! <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>The post <a href="https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/">MoneyBack &#8211; 3 weeks before the end of DSP</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2192</post-id>	</item>
	</channel>
</rss>
