<?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>gabehabe &#187; strings.xml</title>
	<atom:link href="http://www.gabehabe.com/blog/tags/strings-xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gabehabe.com/blog</link>
	<description>Cool blog, bro.</description>
	<lastBuildDate>Wed, 29 Jun 2011 01:26:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Developing for Android, Part I</title>
		<link>http://www.gabehabe.com/blog/developing-for-android-part1/</link>
		<comments>http://www.gabehabe.com/blog/developing-for-android-part1/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 18:21:55 +0000</pubDate>
		<dc:creator>Danny</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[android development]]></category>
		<category><![CDATA[android sdk]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[layout.xml]]></category>
		<category><![CDATA[strings.xml]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.gabehabe.com/blog/?p=84</guid>
		<description><![CDATA[I originally wrote this tutorial for &#60;/dream.in.code&#62;, but I like to get my tutorials around a bit. Welcome to Android. We hope you enjoy your stay. So, first off, a bit of an introduction. This is the first part of (hopefully) many tutorials related to the android platform. In this tutorial, we&#8217;re only going to [...]]]></description>
			<content:encoded><![CDATA[<p>I originally wrote this tutorial for <a href="http://www.dreamincode.net/forums/showtopic130052.htm" target="_blank">&lt;/dream.in.code&gt;</a>, but I like to get my tutorials around a bit.</p>
<h2>Welcome to Android.</h2>
<p> We hope you enjoy your stay.</p>
<p>So, first off, a bit of an introduction. This is the first part of (hopefully) many tutorials related to the android platform. In this tutorial, we&#8217;re only going to cover the very basics: how to design your application, and how to utilise the XML layouts to design your user interface.</p>
<p>Since this series of tutorials is more directed at the code, I&#8217;m not going to cover setup &#038; installation. Instead, <a href="http://developer.android.com/sdk/1.6_r1/index.html">here&#8217;s a link</a> to get yourself set up with the SDK and an emulator.</p>
<p>Personally, I&#8217;ve never really been a huge fan of Java. And when I first tried Android, I wasn&#8217;t too keen. But it&#8217;s come a long way since it was <a href="http://mobile.slashdot.org/article.pl?sid=07/11/12/1626245">first released</a>. Once you get into the android SDK, it begins to get really interesting. Plus, the idea of earning a little bit of cash on the side for designing a little app for your phone has quite a nice appeal. :)</p>
<h2>The market</h2>
<p>The market is awesome. It&#8217;s extremely easy to release and update your applications, and I&#8217;ll be writing a tutorial all about publishing your apps, how to sign them, how to create a jar keystore, all the fun stuff.</p>
<h3>Get started already!!1!one!</h3>
<p>Okay. Enough intro, let&#8217;s get to some development! :)</p>
<p>&#8230;sorry. No programming yet. We&#8217;re going to be reading the project template, and I&#8217;ll be explaining it line for line. It&#8217;s best to take this stuff slow at first, because it&#8217;s so different to a lot of &#8220;regular&#8221; projects. But at least there&#8217;s code! :)</p>
<p>Create a project, you can call it anything, but I&#8217;m going to be following this structure along the series of tutorials:</p>
<h3>layout.xml</h3>
<p>The layout.xml is&#8230; sorta important. It&#8217;s a great way to design your user interfaces, but it&#8217;s not always necessary: you can create your interfaces through pure Java, which is personally my preferred method&#8230; but it&#8217;s still good to know how to use the xml layouts. They help to keep the code for your <strong>activity</strong> more organised. (Coming from a C++/wxWidgets background, I&#8217;m in the habit of creating my programs through pure code, you may prefer the XML process)</p>
<p>Right. Enough rambling. I&#8217;ve analysed the <em>./res/layout/main.xml</em>, and broken it up, line by line.</p>
<p>yep: we just use standard XML to declare the layout:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt; ?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span></pre></div></div>

<p>We use a LinearLayout to define our layout as being, well&#8230; linear:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;linearlayout</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span></pre></div></div>

<p>Next up, we have some properties:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    android:orientation=&quot;vertical&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;</pre></div></div>

<p>Note the three properties:<br />
<strong>android:orientation</strong> &#8212; which direction the layout is filled. Contrary to what you may think, this isn&#8217;t based on the angle of the phone. Using &#8220;vertical&#8221; simply means &#8220;add widget number 2 below widget number 1, add widget number 3 below widget number 2, &#8230; add widget number n below widget number n-1&#8243;. :)<br />
<strong>android:layout_width</strong> &#8212; the width of the object. We&#8217;re going to use &#8220;fill_parent&#8221; to fill the width of the screen<br />
<strong>android:layout_height</strong> &#8212; the height of the object. We&#8217;re going to use &#8220;fill_parent&#8221; again, to fill the height of the screen.<br />
Lastly, we&#8217;re going to close the <code>LinearLayout</code> item. Note we want more items inside the <code>LinearLayout</code>, so we&#8217;re just going to use <code>></code> instead of <code>/></code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    &gt;</pre></div></div>

<p>Next, we&#8217;re going to define a <code>TextView</code>. The <code>TextView</code> is like a Label in .NET, or a wxStaticText in wxWidgets. It basically puts a static piece of text on the screen.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;textview</span> <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;@string/hello&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>You&#8217;ll notice it&#8217;s pretty similar to how we defined the <code>LinearLayout</code>. Differences:<br />
<strong>android:layout_height=&#8221;wrap_content&#8221;</strong> &#8212; the TextView will be resized according to the text it displays. The longer the string, the taller the View.<br />
<strong>android:text=&#8221;@string/hello&#8221;</strong> &#8212; the string to display. <code>@string</code> refers to the <em>./res/values/strings.xml</em> file. (More on this later)<br />
<strong>/></strong> &#8212; this time, we&#8217;re not putting any other items inside it, so we can close it off XML stylee. We could just as easily use</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;textview</span> ... <span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/textview<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p> but it seems a little pointless here. :)</p>
<p>Since that&#8217;s all we want in the <code>LinearLayout</code>, we&#8217;re going to close our layout off:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;</pre></div></div>

</linearlayout></pre>
<h3>strings.xml</h3>
<p>This one's much simpler. Put simply, this file contains strings which are built in to the application at compile time. Note the <strong>hello</strong> string, which we referenced in our <code>TextView</code> in <code>./res/layout/main.xml</code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt; ?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hello&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Hello World, dic_tut1!<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;app_name&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>dic_tut1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h3>The Java!</h3>
<p>Lastly, we're going to put our layout together in the code. I've commented this bit up, so it's easy for you to understand.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">dreamincode.tutorials.part_one</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Activity: the &quot;main&quot; part of the application</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Bundle: stores a &quot;saved state&quot; for your app to remember how it was when moved to the background</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> dic_tut1 <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// inheriting the Activity class</span>
    <span style="color: #008000; font-style: italic; font-weight: bold;">/** Called when the activity is first created. */</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// consider this the &quot;entry point&quot; (main) of your application</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// call the super to restore the state (does the work for you)</span>
        setContentView<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// set the main content view to ./res/layout/main.xml</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>That's all for now!</h3>
<p>There's obviously more to it than this, things such as the <strong>AndroidManifest.xml</strong> file, but I'm not going to go into that now. We'll dive into that as and when we need it, it's really rather trivial and honestly nothing to worry about. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gabehabe.com/blog/developing-for-android-part1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

