<?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>Android Development &#187; Code Examples</title>
	<atom:link href="http://www.androiddevelopment.org/category/code-examples/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.androiddevelopment.org</link>
	<description>Applications made for Android</description>
	<lastBuildDate>Thu, 29 Jul 2010 11:59:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Android Development Demo: &#8220;DialANumber&#8221; &#8211; How to write your own very first Android program &#8211; Made Simple!</title>
		<link>http://www.androiddevelopment.org/2008/10/21/android-development-demo-dialanumber-how-to-write-your-own-very-first-android-program-made-simple/</link>
		<comments>http://www.androiddevelopment.org/2008/10/21/android-development-demo-dialanumber-how-to-write-your-own-very-first-android-program-made-simple/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 08:41:50 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Code Examples]]></category>

		<guid isPermaLink="false">http://www.androiddevelopment.org/2008/10/21/android-development-demo-dialanumber-how-to-write-your-own-very-first-android-program-made-simple/</guid>
		<description><![CDATA[
			
				
			
		
While I think the Android development examples are not really good and straight forward perhaps some of you come along with them. However, I would like to provide you a very very simple example here on how to write your own first Android program.
This is technically very easy. Once you got Eclipse and Android installed [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.androiddevelopment.org%2F2008%2F10%2F21%2Fandroid-development-demo-dialanumber-how-to-write-your-own-very-first-android-program-made-simple%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.androiddevelopment.org%2F2008%2F10%2F21%2Fandroid-development-demo-dialanumber-how-to-write-your-own-very-first-android-program-made-simple%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>While I think the Android development examples are not really good and straight forward perhaps some of you come along with them. However, I would like to provide you a very very simple example here on how to write your own first Android program.</p>
<p>This is technically very easy. Once you got Eclipse and Android installed and running on your computer (I use a Mac OS Leopard powered MacBook but you can use a Microsoft Windows XP/Vista/etc. PC as well) you just start Eclipse. Now you just go to &#8220;<code>New &raquo; Project... &raquo; Android &raquo; Android Project...</code>&#8221; and enter the required data. Once you are done the result might look like this:</p>
<p><img src='http://www.androiddevelopment.org/wp-content/uploads/2008/10/dialanumber_1.png' alt='Android Development Demo: “DialANumber”' /></p>
<p>Now you can start writing and customize the default &#8220;Hello World&#8221; a.k.a. &#8220;Hello Android&#8221; app which just shows a text field. If you are really really lazy you could also copy/paste the following code:</p>
<p><code><br />
package com.DialANumber;</p>
<p>import android.app.Activity;<br />
import android.content.Intent;<br />
import android.net.Uri;<br />
import android.os.Bundle;<br />
import android.view.KeyEvent;<br />
import android.view.View;<br />
import android.widget.Button;<br />
import android.widget.EditText;<br />
import android.widget.LinearLayout;</p>
<p>public class DialANumber extends Activity {<br />
&nbsp;&nbsp;EditText mEditText_number = null;<br />
&nbsp;&nbsp;LinearLayout mLinearLayout_no_button = null;<br />
&nbsp;&nbsp;Button mButton_dial = null;</p>
<p>&nbsp;&nbsp;/** Called when the activity is first created. */<br />
&nbsp;&nbsp;@Override<br />
&nbsp;&nbsp;public void onCreate(Bundle savedInstanceState) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;super.onCreate(savedInstanceState);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;mLinearLayout_no_button = new LinearLayout(this);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;mEditText_number = new EditText(this);<br />
&nbsp;&nbsp;&nbsp;&nbsp;mEditText_number.setText("5551222");<br />
&nbsp;&nbsp;&nbsp;&nbsp;mLinearLayout_no_button.addView(mEditText_number);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;mButton_dial = new Button(this);<br />
&nbsp;&nbsp;&nbsp;&nbsp;mButton_dial.setText("Dial!");<br />
&nbsp;&nbsp;&nbsp;&nbsp;mLinearLayout_no_button.addView(mButton_dial);<br />
&nbsp;&nbsp;&nbsp;&nbsp;mButton_dial.setOnClickListener(new View.OnClickListener() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public void onClick(View v) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;performDial();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;});</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;setContentView(mLinearLayout_no_button);<br />
&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;public boolean onKeyDown(int keyCode, KeyEvent event) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (keyCode == KeyEvent.KEYCODE_CALL) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;performDial();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;return false;<br />
&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;public void performDial(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;if(mEditText_number!=null){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + mEditText_number.getText())));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} catch (Exception e) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}//if<br />
&nbsp;&nbsp;}<br />
}<br />
</code></p>
<p>That was quick! <img src='http://www.androiddevelopment.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now you should create a debug runtime configuration which can be done at &#8220;<strong>Run &raquo; Debug Configurations&#8230;</strong>&#8220;. Here you select &#8220;<strong>Android Application</strong>&#8221; and press &#8220;<strong>New</strong>&#8220;. Enter a name and select the &#8220;<strong>DialANumber</strong>&#8221; project. Launching the default Activity might be a good idea as we not know what the f*** it means right now. <img src='http://www.androiddevelopment.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  So just hit &#8220;<strong>Apply</strong>&#8221; and &#8220;<strong>Debug</strong>&#8221; and the program will be started in the Android simulator. To give you a clue how that looks like here are some screen shots:</p>
<p><img src='http://www.androiddevelopment.org/wp-content/uploads/2008/10/dialanumber_2.png' alt='Android Development Demo: “DialANumber”' /></p>
<p><img src='http://www.androiddevelopment.org/wp-content/uploads/2008/10/dialanumber_3.png' alt='Android Development Demo: “DialANumber”' /></p>
<p>As there is an EditField for the phone number which can be modified you can also enter a new phone number in there. An example of this comes here:</p>
<p><img src='http://www.androiddevelopment.org/wp-content/uploads/2008/10/dialanumber_4.png' alt='Android Development Demo: “DialANumber”' /></p>
<p><img src='http://www.androiddevelopment.org/wp-content/uploads/2008/10/dialanumber_5.png' alt='Android Development Demo: “DialANumber”' /></p>
<p>As everyone can see we are able to dial the number in two different ways:</p>
<ol>
<li>Hit the &#8220;Dial!&#8221; button next to the input field.</li>
<li>Hit the &#8220;green dial&#8221; button on the bottom of the device.</li>
</ol>
<p>Here is an illustration of this:</p>
<p><img src='http://www.androiddevelopment.org/wp-content/uploads/2008/10/dialanumber_4_modified.png' alt='Android Development Demo: “DialANumber” - How to write your own very first Android program - Made Simple!' /></p>
<p>That&#8217;s it. Pretty easy, huh? <img src='http://www.androiddevelopment.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I am looking forward to find some time in the near future to pimp this example a bit. I am thinking of a number field filter adding (which looks a bit confusing in the API documentation) or something else. Suggestions are welcome!</p>
<p>In case someone is <del datetime="2008-10-21T07:31:10+00:00">really lazy</del> interested you can download the whole example project here: <a href='http://www.androiddevelopment.org/wp-content/uploads/2008/10/dialanumber.zip' title='Android Development Demo: DialANumber - How to write your own very first Android program - Made Simple!'>dialanumber.zip</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.androiddevelopment.org/2008/10/21/android-development-demo-dialanumber-how-to-write-your-own-very-first-android-program-made-simple/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>
