<?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>Webdevelopment at huuah.com &#187; Android</title>
	<atom:link href="http://huuah.com/category/android/feed/" rel="self" type="application/rss+xml" />
	<link>http://huuah.com</link>
	<description>webdevelopment, cms, php, javascript etc</description>
	<lastBuildDate>Sun, 20 Nov 2011 20:30:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>The basics of Android intents and activities</title>
		<link>http://huuah.com/the-basics-of-android-intents-and-activities/</link>
		<comments>http://huuah.com/the-basics-of-android-intents-and-activities/#comments</comments>
		<pubDate>Sun, 30 May 2010 12:58:10 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[activity]]></category>
		<category><![CDATA[intent]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=665</guid>
		<description><![CDATA[<p>Intents can among many things be used to start op a new user interface in your Android App. If you are using a MVC technique, you would like the view part to the separated into classes for itself.  To do this, there is three basic steps to make:</p>
<p>- Create &#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Intents can among many things be used to start op a new user interface in your Android App. If you are using a MVC technique, you would like the view part to the separated into classes for itself.  To do this, there is three basic steps to make:</p>
<p>- Create a new class for the activity<br />
- Add the class to the Android Manifest<br />
- Start the activity</p>
<a name="Create+a+class+for+the+user+interface"></a><h1>Create a class for the user interface</h1>
<p>Lets call this file UI:</p>
<pre class="brush: java; title: ; notranslate">
import android.app.Activity;

public class UI extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // type your magic code here
    }

}
</pre>
<p>That it basically it. A class extending the Activity &#8211; the onCreate is called when the activity is started.<br />
NB: the super.onCreate is very important &#8211; without it the code will fail to run!</p>
<a name="Editing+the+AndroidManifest.xml"></a><h1>Editing the AndroidManifest.xml</h1>
<p>The register the intent in the application, we have to edit the AndroidManifest.xml file like this:</p>
<pre class="brush: xml; title: ; notranslate">
...
&lt;application...&gt;
        ...
        &lt;activity android:name=&quot;.UI&quot; android:label=&quot;@string/app_name&quot;&gt;
        &lt;/activity&gt;
        ...
&lt;/application&gt;
</pre>
<p>This enables us to access the UI intent created earlier.</p>
<a name="Starting+the+activity"></a><h1>Starting the activity</h1>
<p>All we have to do now, is to start the new intent. This can be done with the startActivity()-function like this:</p>
<pre class="brush: java; title: ; notranslate">
...
startActivity(new Intent(this, UI.class));
...
</pre>
<p>I hope this small guide is helpful to you. If you would like an example with more details, please let me know</p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/the-basics-of-android-intents-and-activities/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using SQLite from your Android App</title>
		<link>http://huuah.com/using-sqlite-from-your-android-app/</link>
		<comments>http://huuah.com/using-sqlite-from-your-android-app/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 12:46:27 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=641</guid>
		<description><![CDATA[<p>So, how do you use the SQLite database from your Android App? Go google! &#8211; well, been there done that. It took me many hours getting it to work &#8211; perhaps because I made some mistakes &#8211; so I will try and give a crash course in how to connect &#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>So, how do you use the SQLite database from your Android App? Go google! &#8211; well, been there done that. It took me many hours getting it to work &#8211; perhaps because I made some mistakes &#8211; so I will try and give a crash course in how to connect to a SQLite database from an Android Application.</p>
<a name="The+basic+databaseHandler"></a><h1>The basic databaseHandler</h1>
<p>There are properly tons of ways to make a databaseHandler and I will not discuss why and when to use what. Use my examples as you want or if you want to.</p>
<p>The databaseHandler is the class that handles the connection from the application to the database.</p>
<p>This is the most basic database handle class:</p>
<pre class="brush: java; title: ; notranslate">

package huuah.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.SQLException;

public class databaseHelper extends SQLiteOpenHelper {

  private static final String DBNAME = &quot;myfancydatabase&quot;;
  private databaseHelper myDBHelper;
  private SQLiteDatabase myDB; 

  private final Context myContext;

  public databaseHelper(Context context) {
    super(context, DBNAME, null, 2);
    this.myContext = context;
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  }

  public databaseHelper open() throws SQLException {
     myDBHelper = new databaseHelper(myContext);
     myDB = myDBHelper.getWritableDatabase();
     return this;
  }
}
</pre>
<p>When the open() function is called, it will activate the constructor and a new database (in this case named &#8216;myfancydatabase&#8217;) will be created inside the database path for your app.</p>
<p>The database path is located in /data/data/YOURPACKAGENAME/databases/.</p>
<p>To run the code add something like this to your application:</p>
<pre class="brush: java; title: ; notranslate">
...
import huuah.db.databaseHelper;
...
databaseHelper dbCon = new databaseHelper(this);
dbCon.open();
...
</pre>
<p>Use the DDMS in Eclipse or the ADB tool to check if the database is created correctly.</p>
<a name="Copying+from+assets+to+database+path"></a><h1>Copying from assets to database path</h1>
<p>What if we would like to distribute the application with a default database? Almost as simple as creating a new. Copy your SQLite database to the assets folder of your project. From here we will copy it to the correct database folder on the phone.</p>
<pre class="brush: java; title: ; notranslate">
...
  public void createDatabase() throws IOException {

    InputStream assetsDB = myContext.getAssets().open(&quot;localdb&quot;);
    OutputStream dbOut = new FileOutputStream(&quot;/data/data/huuah.db/database/myfancydatabase&quot;);

    byte[] buffer = new byte[1024];
    int length;
    while ((length = assetsDB.read(buffer))&gt;0){
      dbOut.write(buffer, 0, length);
    }

    dbOut.flush();
    dbOut.close();
    assetsDB.close();
}
...
</pre>
<p>This will copy the database &#8216;localdb&#8217; found in the assets folder and copy it to the database folder of my huuah.db package and naming it myfancydatabase. All done.</p>
<a name="Using+DDMS+or+the+ADB+tool"></a><h1>Using DDMS or the ADB tool</h1>
<p>Sometimes it is a good idea to check if your files and databases are created properly. This can be done with the DDMS in the Eclipse IDE or with the ADB tool.</p>
<a name="Eclipse+DDMS"></a><h2>Eclipse DDMS</h2>
<p>Go to the Window-menu, select Open Perspective and click the &#8220;Other&#8221; option. Select the DDMS option and click OK. This will open up a File Explorer and some other windows. The File Explorer can be used to view, delete and copy to and from the emulator by pulling or pushing files.</p>
<a name="ADB+tool"></a><h2>ADB tool</h2>
<p>The adb-tool can, among many things, be used for file exploring. Open a adb shell and list the content of the database folder like this:</p>
<pre class="brush: plain; title: ; notranslate">
$ adb shell
# cd data/data/huuah.db/databases
# ls
myfancydatabase
#
</pre>
<a name="Creating+a+SQLite+database+with+a+Firefox+plugin"></a><h1>Creating a SQLite database with a Firefox plugin</h1>
<p>If your are using Firefox, there is a great simple plugin that lets your create and edit SQLite database. <a href="https://addons.mozilla.org/addon/5817">It can be found here</a>. When downloaded and installed, goto the tools menu in Firefox and select the SQLite manager and your are ready. </p>
<p>There is only one thing you must remember, when creating the databases from scratch like this, is to manually create the android structure. This is done by running these to SQL commands:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE TABLE &quot;android_metadata&quot; (&quot;locale&quot; TEXT DEFAULT 'en_US');
INSERT INTO &quot;android_metadata&quot; VALUES ('en_US');
</pre>
<p>Close and save the database, and copy the file to your assets folder.</p>
<a name="Where+I+got+stuck"></a><h1>Where I got stuck</h1>
<p>I ran into quite a few obstacles when making the database connection for the very first time. I did find some answers as well:</p>
<a name="Problem%3A+public+type+databaseHelper+must+be+definded"></a><h2>Problem: public type databaseHelper must be definded</h2>
<p>Solution: Well, I wasn&#8217;t thinking when creating my databaseHelper, so I just wrote it in the same file as my main function. Don&#8217;t do this. Bad idea. New classes must be placed in its own .java file.</p>
<a name="Problem%3A+I+was+getting+loads+of+%26%238220%3Bdatabase+failure+14%26%238243%3B"></a><h2>Problem: I was getting loads of &#8220;database failure 14&#8243;</h2>
<p>Solution: Don&#8217;t manually create the /data/data/PACKAGENAME/databases directory. User rights on the databases folder will be wrong and your are not allowed to write to the directory from your Android App. Remove the directory and let the Android software create it for you.</p>
<a name="The+end"></a><h1>The end</h1>
<p>I hope your found my post useful. Please post any comments you may have.</p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/using-sqlite-from-your-android-app/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Android Progress Bar and Thread updating</title>
		<link>http://huuah.com/android-progress-bar-and-thread-updating/</link>
		<comments>http://huuah.com/android-progress-bar-and-thread-updating/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 11:43:38 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=606</guid>
		<description><![CDATA[<p>The progress bar is useful for telling users that your Android Application is working on a task that might take a little longer than the usual tasks.</p>
<p>A progress bar is quit easy to make, which I have described here is the <a href="/dialog-boxes-in-android/">Dialog Boxes post here</a> and I will therefor &#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>The progress bar is useful for telling users that your Android Application is working on a task that might take a little longer than the usual tasks.</p>
<p>A progress bar is quit easy to make, which I have described here is the <a href="/dialog-boxes-in-android/">Dialog Boxes post here</a> and I will therefor not go into details with this.</p>
<a name="Simple+test+layout"></a><h1>Simple test layout</h1>
<p>I have created a simple test layout like this:<br />
<img src="/images/progress1.png" alt="Progress Bar Test Layout" /></p>
<p>XML layout:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:orientation=&quot;vertical&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    &gt;

&lt;TextView android:id=&quot;@+id/TextView02&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;Maximum value&quot;&gt;&lt;/TextView&gt;

&lt;EditText android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;100&quot; android:id=&quot;@+id/maximum&quot;&gt;&lt;/EditText&gt;

&lt;TextView android:id=&quot;@+id/TextView01&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;Increment by&quot;&gt;&lt;/TextView&gt;

&lt;EditText android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;5&quot; android:id=&quot;@+id/increment&quot;&gt;&lt;/EditText&gt;

&lt;Button android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;Start&quot; android:id=&quot;@+id/startbtn&quot;&gt;&lt;/Button&gt;

&lt;/LinearLayout&gt;
</pre>
<p>There are two text fields. One to set the maximum value of the progress bar and one to set the increment value. When pushing the Start button a progress bar is displayed and in this example it will just update the progress bar every half a second (500ms) to demonstrate the result.</p>
<a name="Updating+the+progress+bar"></a><h1>Updating the progress bar</h1>
<p>To update the progress bar in the background, while something else is running the application has to use threads. I will be setting up a thread when the Start button is clicked. The thread will then execute some code, in this case just a simple handler that will update the progress bar, and when finished the thread will terminate itself.</p>
<p>When the Start button is activated the application will display a progress bar &#8211; I have set a maximum value of 200 and a increment value of 14:<br />
<img src="/images/progress2.png" alt="Progress Bar Updating" /></p>
<a name="Complete+Java+code"></a><h1>Complete Java code</h1>
<p>The complete java code looks like this. I have added comments in the code, so it should be self explanatory &#8211; if not just post a comment last on this page.</p>
<pre class="brush: java; title: ; notranslate">
package huuah.progressthread;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.app.ProgressDialog;

public class progressthread extends Activity implements OnClickListener {
    ProgressDialog dialog;
    int increment;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button startbtn = (Button) findViewById(R.id.startbtn);
        startbtn.setOnClickListener(this);
    }

    public void onClick(View view) { 

        // get the increment value from the text box
        EditText et = (EditText) findViewById(R.id.increment);
        // convert the text value to a integer
        increment = Integer.parseInt(et.getText().toString());

        dialog = new ProgressDialog(this);
        dialog.setCancelable(true);
        dialog.setMessage(&quot;Loading...&quot;);
        // set the progress to be horizontal
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        // reset the bar to the default value of 0
        dialog.setProgress(0);

        // get the maximum value
        EditText max = (EditText) findViewById(R.id.maximum);
        // convert the text value to a integer
        int maximum = Integer.parseInt(max.getText().toString());
        // set the maximum value
        dialog.setMax(maximum);
        // display the progressbar
        dialog.show();

        // create a thread for updating the progress bar
        Thread background = new Thread (new Runnable() {
           public void run() {
               try {
                   // enter the code to be run while displaying the progressbar.
                   //
                   // This example is just going to increment the progress bar:
                   // So keep running until the progress value reaches maximum value
                   while (dialog.getProgress()&lt;= dialog.getMax()) {
                       // wait 500ms between each update
                       Thread.sleep(500);

                       // active the update handler
                       progressHandler.sendMessage(progressHandler.obtainMessage());
                   }
               } catch (java.lang.InterruptedException e) {
                   // if something fails do something smart
               }
           }
        });

        // start the background thread
        background.start();

    }

    // handler for the background updating
    Handler progressHandler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.incrementProgressBy(increment);
        }
    };
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/android-progress-bar-and-thread-updating/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Dialog boxes in Android</title>
		<link>http://huuah.com/dialog-boxes-in-android/</link>
		<comments>http://huuah.com/dialog-boxes-in-android/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 13:58:46 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=594</guid>
		<description><![CDATA[<a name="Dialog+boxes"></a>Dialog boxes
<p>Showing dialog boxes from an android application can be usefull.</p>
<p>This article will be using a layout like this &#8211; 4 buttons with their own function (complete code id listed last in this article):<br />
</p>
<a name="Info+boxes"></a>Info boxes
<p>An info box is called a Toast on the Android OS. A &#8230;</p>]]></description>
			<content:encoded><![CDATA[<a name="Dialog+boxes"></a><h1>Dialog boxes</h1>
<p>Showing dialog boxes from an android application can be usefull.</p>
<p>This article will be using a layout like this &#8211; 4 buttons with their own function (complete code id listed last in this article):<br />
<img src="/images/androiddialog/dialog.png" alt="Android Dialog Layout" /></p>
<a name="Info+boxes"></a><h1>Info boxes</h1>
<p>An info box is called a Toast on the Android OS. A toast message is a small window that appear in the button half on the device screen. It should only be used as an information service to the user. The window disappears by itself, so as a developer you can not be sure that the user actually sees the message displayed. If you want to user to take action on the popup window, you should use an alert dialog instead &#8211; this is covered later on.</p>
<div class="ww">
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/0470565527?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=0470565527"><img border="0" src="/41i8myyWOQL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=0470565527" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/1430226293?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=1430226293"><img border="0" src="/41BS4S8iYQL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=1430226293" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/1430226595?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=1430226595"><img border="0" src="/41lXdAj5BZL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=1430226595" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/0321673352?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=0321673352"><img border="0" src="/51Sk-mnL5CL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=0321673352" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/144938255X?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=144938255X"><img border="0" src="/41evBpToAaL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=144938255X" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
</div>
<p>The Toast message is very easy to create. The most simple way to display a toast is by calling the maketext()-method like this:</p>
<pre class="brush: java; title: ; notranslate">
...
Toast.makeText(this, &quot;This is the Toast message&quot;, Toast.LENGTH_LONG).show();
...
</pre>
<p>This will display a box like this:<br />
<img src="/images/androiddialog/toast.png" alt="Android Toast" /></p>
<a name="Alert+boxes"></a><h1>Alert boxes</h1>
<p>The Alert box should be use when you want to make sure, that the user reads and takes action on the information window. To display the alert window, can be done like this:</p>
<pre class="brush: java; title: ; notranslate">
...
            // prepare the alert box
            AlertDialog.Builder alertbox = new AlertDialog.Builder(this);

            // set the message to display
            alertbox.setMessage(&quot;This is the alertbox!&quot;);

            // add a neutral button to the alert box and assign a click listener
            alertbox.setNeutralButton(&quot;Ok&quot;, new DialogInterface.OnClickListener() {

                // click listener on the alert box
                public void onClick(DialogInterface arg0, int arg1) {
                    // the button was clicked
                    Toast.makeText(getApplicationContext(), &quot;OK button clicked&quot;, Toast.LENGTH_LONG).show();
                }
            });

            // show it
            alertbox.show();
...
</pre>
<p>This will popup a window like this:<br />
<img src="/images/androiddialog/alert.png" alt="Android Alertbox" /></p>
<p>When is OK button is clicked, it will &#8211; in this example &#8211; show a toast message like this:<br />
<img src="/images/androiddialog/okbtn.png" alt="Android OK toast" /></p>
<a name="Yes%2Fno+boxes"></a><h1>Yes/no boxes</h1>
<p>If one button on the alert dialog isn&#8217;t enough we can use the setPositiveButton() and setNegativeButton() on the AlertDialog Builder like this:</p>
<pre class="brush: java; title: ; notranslate">
...
            // prepare the alert box
            AlertDialog.Builder alertbox = new AlertDialog.Builder(this);

            // set the message to display
            alertbox.setMessage(&quot;This is the alertbox!&quot;);

            // set a positive/yes button and create a listener
            alertbox.setPositiveButton(&quot;Yes&quot;, new DialogInterface.OnClickListener() {

                // do something when the button is clicked
                public void onClick(DialogInterface arg0, int arg1) {
                    Toast.makeText(getApplicationContext(), &quot;'Yes' button clicked&quot;, Toast.LENGTH_SHORT).show();
                }
            });

            // set a negative/no button and create a listener
            alertbox.setNegativeButton(&quot;No&quot;, new DialogInterface.OnClickListener() {

                // do something when the button is clicked
                public void onClick(DialogInterface arg0, int arg1) {
                    Toast.makeText(getApplicationContext(), &quot;'No' button clicked&quot;, Toast.LENGTH_SHORT).show();
                }
            });

            // display box
            alertbox.show();
...
</pre>
<p>This will show a window like this:<br />
<img src="/images/androiddialog/yesno.png" alt="Android Yes/No window" /></p>
<p>When either of the buttons is clicked it will run the assigned listener. Here we have clicked the yes button:<br />
<img src="/images/androiddialog/yesbtn.png" alt="Android Yes toast" /></p>
<a name="Loading+box"></a><h1>Loading box</h1>
<p>If you want to display a loading window or some kind of progress alert it can be done with the ProgressDialog like this:</p>
<pre class="brush: java; title: ; notranslate">
...
            // prepare the dialog box
            ProgressDialog dialog = new ProgressDialog(this);

            // make the progress bar cancelable
            dialog.setCancelable(true);

            // set a message text
            dialog.setMessage(&quot;Loading...&quot;);

            // show it
            dialog.show();
...
</pre>
<p>This will popup a progress window like this:<br />
<img src="/images/androiddialog/progress.png" alt="Android Progress Window" /></p>
<p>This window will not close by itself. You have to make it complete, by running a code that increment the internal counter on the ProgressDialog, so that the progressdialog can calculate the percentage by itself. For this we should use a thread-based application, that runs some code in the background and from there set the progress bar at the given value. This is not covered in this article though.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-2002298237929711";
/* huuah-android 468x60, oprettet 08-02-11 */
google_ad_slot = "0869223127";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<a name="Complete+code"></a><h1>Complete code</h1>
<p>The small code samples above are shown here in the complete formation, including the main.xml layout.</p>
<a name="main.xml"></a><h2>main.xml</h2>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:orientation=&quot;vertical&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    &gt;

&lt;Button android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;Show Toast&quot; android:id=&quot;@+id/toastbtn&quot;&gt;&lt;/Button&gt;
&lt;Button android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;Show Alert&quot; android:id=&quot;@+id/alertbtn&quot;&gt;&lt;/Button&gt;
&lt;Button android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;Show Yes/No&quot; android:id=&quot;@+id/yesnobtn&quot;&gt;&lt;/Button&gt;
&lt;Button android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;Show Progress&quot; android:id=&quot;@+id/progressbtn&quot;&gt;&lt;/Button&gt;
&lt;/LinearLayout&gt;
</pre>
<a name="dialogboxes.java"></a><h2>dialogboxes.java</h2>
<pre class="brush: java; title: ; notranslate">
package huuah.dialogboxes;

import android.app.Activity;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.app.ProgressDialog;

public class dialogboxes extends Activity implements OnClickListener {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // set a click listener on the toast button
        Button toast = (Button) findViewById(R.id.toastbtn);
        toast.setOnClickListener(this);

        // set a click listener on the alert button
        Button alert = (Button) findViewById(R.id.alertbtn);
        alert.setOnClickListener(this);

        // set a click listener on the yesno button
        Button yesno = (Button) findViewById(R.id.yesnobtn);
        yesno.setOnClickListener(this);

        // set a click listener on the progress button
        Button progress = (Button) findViewById(R.id.progressbtn);
        progress.setOnClickListener(this);
    }

    public void onClick(View view) {
        // which button is clicked?

        // the Toast button
        if (view == findViewById(R.id.toastbtn)) {
            // display the toast popup window
            Toast.makeText(this, &quot;This is the Toast message&quot;, Toast.LENGTH_LONG).show();
        }

        // the Alert button the activated
        if (view == findViewById(R.id.alertbtn)) {

            // prepare the alert box
            AlertDialog.Builder alertbox = new AlertDialog.Builder(this);

            // set the message to display
            alertbox.setMessage(&quot;This is the alertbox!&quot;);

            // add a neutral button to the alert box and assign a click listener
            alertbox.setNeutralButton(&quot;Ok&quot;, new DialogInterface.OnClickListener() {

                // click listener on the alert box
                public void onClick(DialogInterface arg0, int arg1) {
                    // the button was clicked
                    Toast.makeText(getApplicationContext(), &quot;OK button clicked&quot;, Toast.LENGTH_LONG).show();
                }
            });

            // show it
            alertbox.show();
        }

        // the yesno button is clicked
        if (view == findViewById(R.id.yesnobtn)) {
            // prepare the alert box
            AlertDialog.Builder alertbox = new AlertDialog.Builder(this);

            // set the message to display
            alertbox.setMessage(&quot;This is the alertbox!&quot;);

            // set a positive/yes button and create a listener
            alertbox.setPositiveButton(&quot;Yes&quot;, new DialogInterface.OnClickListener() {

                // do something when the button is clicked
                public void onClick(DialogInterface arg0, int arg1) {
                    Toast.makeText(getApplicationContext(), &quot;'Yes' button clicked&quot;, Toast.LENGTH_SHORT).show();
                }
            });

            // set a negative/no button and create a listener
            alertbox.setNegativeButton(&quot;No&quot;, new DialogInterface.OnClickListener() {

                // do something when the button is clicked
                public void onClick(DialogInterface arg0, int arg1) {
                    Toast.makeText(getApplicationContext(), &quot;'No' button clicked&quot;, Toast.LENGTH_SHORT).show();
                }
            });

            // display box
            alertbox.show();
        }

        // progress button clicked
        if (view == findViewById(R.id.progressbtn)) {
            // prepare the dialog box
            ProgressDialog dialog = new ProgressDialog(this);

            // make the progress bar cancelable
            dialog.setCancelable(true);

            // set a message text
            dialog.setMessage(&quot;Loading...&quot;);

            // show it
            dialog.show();
        }

    }
}
</pre>
<p>I hope this will the useful. If you want to read more on this subject, then take a look at some of the <a href="http://astore.amazon.co.uk/androidbooks-21">Android books out there</a></p>
<div class="ww">
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/0470565527?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=0470565527"><img border="0" src="/41i8myyWOQL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=0470565527" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/0321673352?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=0321673352"><img border="0" src="/51Sk-mnL5CL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=0321673352" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/1430226293?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=1430226293"><img border="0" src="/41BS4S8iYQL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=1430226293" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/144938255X?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=144938255X"><img border="0" src="/41evBpToAaL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=144938255X" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<div class="am">
<a href="http://www.amazon.co.uk/gp/product/1430226595?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=1430226595"><img border="0" src="/41lXdAj5BZL._SL110_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=1430226595" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/dialog-boxes-in-android/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Android writing and reading files</title>
		<link>http://huuah.com/android-writing-and-reading-files/</link>
		<comments>http://huuah.com/android-writing-and-reading-files/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 14:08:16 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=585</guid>
		<description><![CDATA[<a name="How+to+read+and+write+files+in+you+Android+Application"></a>How to read and write files in you Android Application
<p>When coding an application for the Android system, you will eventually need to store some data on the phones for later use. There are generally two ways of doing this &#8211; either in files or by using a SQLlite database.&#8230;</p>]]></description>
			<content:encoded><![CDATA[<a name="How+to+read+and+write+files+in+you+Android+Application"></a><h1>How to read and write files in you Android Application</h1>
<p>When coding an application for the Android system, you will eventually need to store some data on the phones for later use. There are generally two ways of doing this &#8211; either in files or by using a SQLlite database.</p>
<a name="Write+to+file"></a><h1>Write to file</h1>
<p>So your sitting there with your fancy newly developed application, but all your settings are going back to default values when the program starts. Why not just write the settings to a file and then read the file content when the application starts up.</p>
<p>To do this we need the OutputStream and OutputStreamReader, so lets import them like this:</p>
<pre class="brush: java; title: ; notranslate">
import java.io.OutputStream;
import java.io.OutputStreamWriter;
</pre>
<p>Lets say the application has a save button somewhere and when this is clicked the onClick(View) is called. We can then add some code, to handle the file writing:</p>
<pre class="brush: java; title: ; notranslate">
...
public void onClick(View view) {
...
// try to write the content
try {
  // open myfilename.txt for writing
  OutputStreamWriter out = new OutputStreamWriter(openFileOutput(&quot;myfilename.txt&quot;,0));
  // write the contents on mySettings to the file
  out.write(mySettings);
  // close the file
  out.close();
} catch (java.io.IOException e) {
  //do something if an IOException occurs.
}
</pre>
<p>There you go. The content from the mySettings variable should now be writting to the file myfilename.txt. How the settings come from the application to the mySettings variable is another subject and is not covered here.</p>
<a name="Reading+lines+from+a+file"></a><h1>Reading lines from a file</h1>
<p>Now we have some data information writting to the myfilename.txt-file, that now exits on the Android device.</p>
<p>To read the information from the file, we need to the InputReader, InputReaderStream and BufferedReader, so just import them like this:</p>
<pre class="brush: java; title: ; notranslate">
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
</pre>
<p>All we have to do now, is open the myfilename.txt for reading. This could be done like this:</p>
<pre class="brush: java; title: ; notranslate">
...
  // try opening the myfilename.txt
  try {
    // open the file for reading
    InputStream instream = openFileInput(&quot;myfilename.txt&quot;);

    // if file the available for reading
    if (instream) {
      // prepare the file for reading
      InputStreamReader inputreader = new InputStreamReader(instream);
      BufferedReader buffreader = new BufferedReader(inputreader);

      String line;

      // read every line of the file into the line-variable, on line at the time
      while (( line = buffreader.readLine())) {
        // do something with the settings from the file
      }

    }

    // close the file again
    instream.close();
  } catch (java.io.FileNotFoundException e) {
    // do something if the myfilename.txt does not exits
  }
...
</pre>
<p>We have now read the content of the myfilename.txt and made it available for the application.</p>
<p>To read more about this Android check out <a href="http://astore.amazon.co.uk/androidbooks-21">these books</a>: <a href="http://astore.amazon.co.uk/androidbooks-21">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/android-writing-and-reading-files/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Using TableLayout on Android</title>
		<link>http://huuah.com/using-tablelayout-on-android/</link>
		<comments>http://huuah.com/using-tablelayout-on-android/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 10:55:03 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=518</guid>
		<description><![CDATA[<p>Just like HTML Tables on webpages the TableLayout on Android gives you the option to align Views in a table order with rows and columns.</p>
<p>
<br />

</p>
<a name="My+development+setup+is%3A"></a>My development setup is:
<p>IDE: Eclipse IDE (<a href="/android-development-platform-on-ubuntu-9-10/">setup guide here</a>).<br />
Phone: HTC Hero<br />
Android version: 1.5 HTC Rom</p>
<p>I will be using the &#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Just like HTML Tables on webpages the TableLayout on Android gives you the option to align Views in a table order with rows and columns.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-2002298237929711";
/* huuah-android-tablelayout 468x15, oprettet 09-02-11 */
google_ad_slot = "0435761027";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<a name="My+development+setup+is%3A"></a><h2>My development setup is:</h2>
<p>IDE: Eclipse IDE (<a href="/android-development-platform-on-ubuntu-9-10/">setup guide here</a>).<br />
Phone: HTC Hero<br />
Android version: 1.5 HTC Rom</p>
<p>I will be using the standard Android Project Skeleton in Eclipse as my base setup. This auto creates all the basic files needed, so these will not be covered here.</p>
<a name="TableLayout+on+Android"></a><h1>TableLayout on Android</h1>
<p>The TableLayout is built using the TableLayout and the TableRow commands. There is no TableCols like the &lt;td&gt; tag in HTML. To align your view in columns you have to set the width of the elements and manually control the layout.</p>
<a name="XML+Layout"></a><h1>XML Layout</h1>
<p>To make a basic layout with 2 rows and 4 textview I have a main.xml with this content:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;TableLayout android:id=&quot;@+id/TableLayout01&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot;&gt;

  &lt;TableRow android:id=&quot;@+id/TableRow01&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot;&gt;

    &lt;TextView android:id=&quot;@+id/TextView01&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;textfield 1-1&quot;&gt;&lt;/TextView&gt;
    &lt;TextView android:id=&quot;@+id/TextView02&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;textfield 1-2&quot;&gt;&lt;/TextView&gt;

  &lt;/TableRow&gt;

  &lt;TableRow android:id=&quot;@+id/TableRow02&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot;&gt;

    &lt;TextView android:id=&quot;@+id/TextView03&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;textfield 2-1&quot;&gt;&lt;/TextView&gt;
    &lt;TextView android:id=&quot;@+id/TextView04&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;textfield 2-2&quot;&gt;&lt;/TextView&gt;

  &lt;/TableRow&gt;

&lt;/TableLayout&gt;
</pre>
<p>This creates a layout like this:<br />
<img src="/images/android-tablelayout1.png" alt="Android TableLayout 1" /></p>
<p>So we have now displayed a simple TableLayout.</p>
<a name="Right+aligning+checkboxes"></a><h1>Right aligning checkboxes</h1>
<p>Many apps have a nice clean setup where the checkboxes is right aligned to the screen and this is actually very easy to achieve. You just have to set the width of the textview so it will push the checkbox to the right.</p>
<p>First step is to change the TextView02 to a Checkbox like this:</p>
<pre class="brush: xml; title: ; notranslate">
...
    &lt;TextView android:id=&quot;@+id/TextView01&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;textfield 1-1&quot;&gt;&lt;/TextView&gt;
    &lt;CheckBox android:id=&quot;@+id/CheckBox01&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot;&gt;&lt;/CheckBox&gt;
</pre>
<p>This will output somethings like this:<br />
<img src="/images/android-tablelayout2.png" alt="Android TableLayout 2" /></p>
<p>Now we just have to align the checkbox.</p>
<p>We can do this by setting the width of the previous textfield like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;TableRow android:id=&quot;@+id/TableRow01&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot;&gt;&lt;TextView android:id=&quot;@+id/TextView01&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;textfield 1-1&quot; android:width=&quot;250px&quot;&gt;&lt;/TextView&gt;
</pre>
<p>Notice the <em>width=&#8221;250px&#8221;</em> in the end there. This results in:<br />
<img src="/images/android-tablelayout3.png" alt="Android TableLayout 3" /></p>
<p>But what is the screen size changes? The checkbox will then be placed 250px from the left because the width is hardcoded. Not that great &#8211; but yet very easy to adjust.</p>
<p>On the LayoutTable we can adjust stretching across columns, similar to the colspan tag in HTML.</p>
<pre class="brush: xml; title: ; notranslate">
...
&lt;TableLayout android:id=&quot;@+id/TableLayout01&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;wrap_content&quot;  android:stretchColumns=&quot;0&quot;&gt;
...
</pre>
<p>This will make the first (&#8220;0&#8243;) column stretch as most as needed and allowed by the other elements.:<br />
<img src="/images/android-tablelayout4.png" alt="Android TableLayout 4" /></p>
<p>And with the screen flipped:<br />
<img src="/images/android-tablelayout5.png" alt="Android TableLayout 5" /></p>
<p>Complete XML layout:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:orientation=&quot;vertical&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    &gt;

&lt;TableLayout android:id=&quot;@+id/TableLayout01&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;wrap_content&quot;  android:stretchColumns=&quot;0&quot;&gt;

  &lt;TableRow android:id=&quot;@+id/TableRow01&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot;&gt;
    &lt;TextView android:id=&quot;@+id/TextView01&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;textfield 1-1&quot;&gt;&lt;/TextView&gt;

    &lt;CheckBox android:id=&quot;@+id/CheckBox01&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot;&gt;&lt;/CheckBox&gt;
  &lt;/TableRow&gt;

  &lt;TableRow android:id=&quot;@+id/TableRow02&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot;&gt;
    &lt;TextView android:id=&quot;@+id/TextView03&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;textfield 2-1&quot;&gt;&lt;/TextView&gt;
    &lt;TextView android:id=&quot;@+id/TextView04&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;textfield 2-2&quot;&gt;&lt;/TextView&gt;

  &lt;/TableRow&gt;

&lt;/TableLayout&gt;
&lt;/LinearLayout&gt;
</pre>
<a name="Appending+rows+dynamically"></a><h1>Appending rows dynamically</h1>
<p>Lets say you want to add rows to the TableLayout on depend during your app. No problem.</p>
<p>Add a button at the top of your application like this:</p>
<pre class="brush: xml; title: ; notranslate">
  &lt;Button android:id=&quot;@+id/Button01&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;Add row&quot;&gt;&lt;/Button&gt;

  &lt;ScrollView android:id=&quot;@+id/ScrollView01&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot;&gt;

    &lt;TableLayout android:id=&quot;@+id/TableLayout01&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;wrap_content&quot; android:stretchColumns=&quot;0&quot;&gt;

      &lt;TableRow android:id=&quot;@+id/TableRow01&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot;&gt;
        &lt;TextView android:id=&quot;@+id/TextView01&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;textfield 1-1&quot;&gt;&lt;/TextView&gt;

        &lt;CheckBox android:id=&quot;@+id/CheckBox01&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot;&gt;&lt;/CheckBox&gt;
      &lt;/TableRow&gt;

    &lt;/TableLayout&gt;
  &lt;/ScrollView&gt;
</pre>
<p>There is now a button available for handling clicks from the user and the TableLayout has been wrapped in a ScrollView which enables the scroll functionality.</p>
<p>Now for some Java code</p>
<pre class="brush: java; title: ; notranslate">
package huuah.tablelayout;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TableLayout;
import android.widget.TextView;
import android.view.View;

import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;

public class tablelayout extends Activity implements OnClickListener {
    /** Called when the activity is first created. */

    //initialize a button and a counter
    Button btn;
    int counter = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // setup the layout
        setContentView(R.layout.main);

        // add a click-listener on the button
        btn = (Button) findViewById(R.id.Button01);
        btn.setOnClickListener(this);        

    }

    // run when the button is clicked
    public void onClick(View view) {

        // get a reference for the TableLayout
        TableLayout table = (TableLayout) findViewById(R.id.TableLayout01);

        // create a new TableRow
        TableRow row = new TableRow(this);

        // count the counter up by one
        counter++;

        // create a new TextView
        TextView t = new TextView(this);
        // set the text to &quot;text xx&quot;
        t.setText(&quot;text &quot; + counter);

        // create a CheckBox
        CheckBox c = new CheckBox(this);

        // add the TextView and the CheckBox to the new TableRow
        row.addView(t);
        row.addView(c);

        // add the TableRow to the TableLayout
        table.addView(row,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    }
}
</pre>
<p><img src="/images/android-tablelayout6.png" alt="Android TableLayout 6" /></p>
<p>So whenever the button is clicked, it adds a new row to the TableLayout and notice the Scrollbar from the ScrollView.</p>
<p>If you want more information and TableLayout and placement techniques I can recommend reading:<br />
<a href="http://www.amazon.co.uk/gp/product/1430224193?ie=UTF8&#038;tag=huuah-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=1430224193"><img border="0" src="/images/51OlepXf2jL._SL160_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=huuah-21&#038;l=as2&#038;o=2&#038;a=1430224193" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></p>
<p>Thats it for now. Enjoy coding and please post some comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/using-tablelayout-on-android/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Android apps</title>
		<link>http://huuah.com/android-apps/</link>
		<comments>http://huuah.com/android-apps/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 17:52:11 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=531</guid>
		<description><![CDATA[<p>The Android market contains loads of apps ready to install. It can sometime be difficult to find the right app for the job, so I will here list the Android apps that I use.</p>
<p>For installing and managing files I am using<br />
- <em>appInstaller</em><br />
- <em>ASTRO</em></p>
<p>Games and fun:<br />
- &#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>The Android market contains loads of apps ready to install. It can sometime be difficult to find the right app for the job, so I will here list the Android apps that I use.</p>
<p>For installing and managing files I am using<br />
- <em>appInstaller</em><br />
- <em>ASTRO</em></p>
<p>Games and fun:<br />
- <em>Google Sky Map</em>: This it really a must have app.<br />
- <em>Jewels</em>: Fun little game where to have to align colored boxes in row to have them disappear. Quite difficult actually.<br />
- <em>Teeter and Labyrinth</em>: Control a metal ball on a board and avoid the holes.</p>
<p>Programs:<br />
- <em>Barcode Scanner</em>: Point the camera at a barcode and it will scan it and search the web afterwards.<br />
- <em>Compass</em>: Well &#8211; a compass.<br />
- <em>Contact2Sim</em>: Copy contacts from the phone to the sim card.<br />
- <em>Ear</em>: Very nice apps to handle profile settings (ringtones, messagesignals etc).<br />
- <em>Fring</em>: Connect to Skype and other services where ever you are.<br />
- <em>Handcent Sms</em>: SMS replacement for the built-in sms apps. Better customization options.<br />
- <em>Is It On?</em>: Widget that delivers status and shortcuts to GPS-status, wireless, bluetooth etc.<br />
- <em>K-9 Mail</em>: Replacement for the built in email-client. I prefers the K-9 because it has a better update function when checking for new mail.<br />
- <em>NetCounter</em>: Keeps track on the bandwidth usage and alert you if the limit is close.<br />
- <em>Scanlife</em>: Another barcode scanner.<br />
- <em>Shopping List Plus</em>: Add items to a shopping list. Easy check function when the item is found at the shop.<br />
- <em>Sudoku Free</em>: Well. You know.<br />
- <em>TaskPanel</em>: Task killer that support ignore- and autokill-lists.</p>
<p>This is the apps that I am using at the moment. Please post some good apps, that I should check out.</p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/android-apps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android development platform on Ubuntu 9.10</title>
		<link>http://huuah.com/android-development-platform-on-ubuntu-9-10/</link>
		<comments>http://huuah.com/android-development-platform-on-ubuntu-9-10/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 22:25:15 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[ide]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=492</guid>
		<description><![CDATA[<p>Here is a quick guide on installing a development environment (using the Eclipse IDE) for Android applications on Ubuntu 9.10.</p>
<p>1. Open the Synaptic package manager and install the <code>sun-java6-jdk</code> and the <code>eclipse</code> package (and of-course accept the depending packages).</p>
<p>2. Verify that you have a working java enviroment by &#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Here is a quick guide on installing a development environment (using the Eclipse IDE) for Android applications on Ubuntu 9.10.</p>
<p>1. Open the Synaptic package manager and install the <code>sun-java6-jdk</code> and the <code>eclipse</code> package (and of-course accept the depending packages).</p>
<p>2. Verify that you have a working java enviroment by running <code>java -version</code> in a terminal.</p>
<p>3. Download the lasted version of the Android SDK at android.com (<a href="http://developer.android.com/sdk/index.html">http://developer.android.com/sdk/index.html</a>).</p>
<p>4. Unpack the SDK file to your home directory (or somewhere else &#8211; its your choice)</p>
<p>5. Open the newly installed Eclipse IDE.</p>
<p>6. In Eclipse goto the <code>Help</code> menu and select the <code>Install New Software</code></p>
<p>7. Click <code>Add</code> and create a site with this url: <strong>http://download.eclipse.org/releases/galileo/</strong></p>
<p>8. Now search for <code>wst</code> and install the <code>WST Server Adapters</code>.</p>
<p>9. Add another site with this url: <strong>http://dl-ssl.google.com/android/eclipse/</strong> and install the <code>Android Development Tools</code>.</p>
<p>10. Select the <code>Window</code> menu in Eclipse and open the <code>preferences</code>. Select the Android section and set the SDK location to the directory where the SDK in unpacked (in sted 4).</p>
<p>11. Open a terminal/command prompt, go to the tools directory inside the SDK (which we unpacked in step 4) and run the <code>android</code> program. Select the <code>Settings</code> menu and check the <code>Force https ..</code> field. Then go to the <code>Available Packages</code> and select which version(s) that you want to develop to. When done, close the program.</p>
<p>The IDE is now ready to go. </p>
<p>Further reading could be the Hello World tutorial over at android.com (<a href="http://developer.android.com/guide/tutorials/hello-world.html">http://developer.android.com/guide/tutorials/hello-world.html</a>) that also lists how to setup an emulator for testing the applications. (something like <code>android create avd --target 1 --name my_avd</code>)</p>
<p>I hope this can help you get started.</p>
<p>Please post any comments you may have.</p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/android-development-platform-on-ubuntu-9-10/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

