<?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; development</title>
	<atom:link href="http://huuah.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://huuah.com</link>
	<description>webdevelopment, cms, php, javascript etc</description>
	<lastBuildDate>Sat, 04 Sep 2010 22:55:27 +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>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;">
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;">
...
&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;">
...
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>0</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;">

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;">
...
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;">
...
  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;">
$ 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;">
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>5</slash:comments>
		</item>
		<item>
		<title>Howto float your CSS</title>
		<link>http://huuah.com/howto-float-your-css/</link>
		<comments>http://huuah.com/howto-float-your-css/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 19:41:13 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=611</guid>
		<description><![CDATA[<p>Float left. Float right. What to do and why? Well read on &#8230;</p>
<a name="How+to+float+it"></a>How to float it
<p>Well &#8211; it can sometimes be quite difficult to understand how the float universe works. I will try to give some basic pointers and examples on the float left and float right&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Float left. Float right. What to do and why? Well read on &#8230;</p>
<a name="How+to+float+it"></a><h1>How to float it</h1>
<p>Well &#8211; it can sometimes be quite difficult to understand how the float universe works. I will try to give some basic pointers and examples on the float left and float right technique and how it reacts in the layout.</p>
<p><SCRIPT charset="utf-8" type="text/javascript" src="http://ws.amazon.co.uk/widgets/q?ServiceVersion=20070822&#038;MarketPlace=GB&#038;ID=V20070822/GB/huuah-21/8006/871a18af-2ef7-40ff-b192-f5732c864791"> </SCRIPT> <NOSCRIPT><A HREF="http://ws.amazon.co.uk/widgets/q?ServiceVersion=20070822&#038;MarketPlace=GB&#038;ID=V20070822%2FGB%2Fhuuah-21%2F8006%2F871a18af-2ef7-40ff-b192-f5732c864791&#038;Operation=NoScript">Amazon.co.uk Widgets</A></NOSCRIPT></p>
<a name="The+basic+of+id+and+classes"></a><h1>The basic of id and classes</h1>
<p>There are two ways to access HTML elements from CSS. You can either use id&#8217;s or class&#8217;es. Almost every HTML tag, if not all, allows the assignment of an id or class name. When element has an id or class, it can be accessed from CSS by using . or #.</p>
<p>ID are accessed with # (hash). Lets say we have a &lt;div&gt;-tag with the id set to mydiv:</p>
<pre class="brush: xml;">
&lt;div id=&quot;mydiv&quot;&gt;some content here&lt;/div&gt;
</pre>
<p>The mydiv can then be access like this from CSS</p>
<pre class="brush: css;">
#mydiv {
  width: 100px;
  height: 100px;
}
</pre>
<p>If we are using a class instead of an id, the code would lookup like this:</p>
<pre class="brush: xml;">
&lt;div class=&quot;mydiv&quot;&gt;some content here&lt;/div&gt;
</pre>
<p>And</p>
<pre class="brush: css;">
.mydiv {
  width: 100px;
  height: 100px;
}
</pre>
<p>id&#8217;s and class&#8217;es will not be covered in more details here.</p>
<a name="Starting+point"></a><h1>Starting point</h1>
<p>This article will use the following HTML as a starting point. It holds a simple div-&#8221;container&#8221; with contains another 3 divs.</p>
<pre class="brush: xml;">
&lt;div class=&quot;container&quot;&gt;
  &lt;div class=&quot;class1&quot;&gt;This is the first class&lt;/div&gt;
  &lt;div class=&quot;class2&quot;&gt;This is the second class&lt;/div&gt;
  &lt;div class=&quot;class3&quot;&gt;This is the third class&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>Without any CSS it would look like this:</p>
<div class="container">
<div class="class1">This is the first class</div>
<div class="class2">This is the second class</div>
<div class="class3">This is the third class</div>
</div>
<p>Not really that pretty and nice as we would like it to be, right?</p>
<a name="Basic+styling"></a><h1>Basic styling</h1>
<p>Lets do some basic styling of the above code, to better see what&#8217;s going on.</p>
<pre class="brush: css;">
.class1 {
  width: 200px;
  background-color: light-grey;
}
.class2 {
  width: 300px;
  background-color: white;
}
.class3 {
  width: 500px;
  background-color: grey;
}
</pre>
<p>This outputs:</p>
<div class="container1">
<div class="class1">This is the first class</div>
<div class="class2">This is the second class</div>
<div class="class3">This is the third class</div>
</div>
<p>Okay &#8211; now we can better see the difference between the 3 divs.</p>
<a name="Lets+float+it"></a><h1>Lets float it</h1>
<p>When floating left, the selected element will be placed along the left side of the next element.<br />
When floating right, the selected element will be placed along the right side of the next element.</p>
<p>Left floating the first class:</p>
<pre class="brush: css;">
.class1 {
  width: 200px;
  background-color: light-grey;
  float: left;
}
</pre>
<div class="container2">
<div class="class1">This is the first class</div>
<div class="class2">This is the second class</div>
<div class="class3">This is the third class</div>
</div>
<p>Okay, that went kinda like expected. Although &#8211; the class2 has a width set to 300px, so why does it wrap like that, when it should have enough space &#8211; the class1 is 200px and the class3 is 500px, so class1 and class2 should will up the exact same space as class3 below. </p>
<p>This is one of those questions I used to ask a friend of mine over at <a href="http://www.spiced2.com">spiced2.com</a> and he always answered &#8220;when in doubt, float left&#8221;. Ok then. Lets float class2 left as well:</p>
<div class="container3">
<div class="class1">This is the first class</div>
<div class="class2">This is the second class</div>
<div class="class3">This is the third class</div>
</div>
<pre class="brush: css;">
.class1 {
          width: 200px;
          background-color: #DEDEDE;
          float: left;
}
.class2 {
          width: 300px;
          background-color: #006699;
          float: left;
}
.class3 {
          width: 500px;
          background-color: #009900;
}
</pre>
<p>Now it&#8217;s a lot better, but what will happen if we try to float right?</p>
<div class="container4">
<div class="class1">This is the first class</div>
<div class="class2">This is the second class</div>
<div class="class3">This is the third class</div>
</div>
<p>The first class is now floating right, and is therefor aligned to the right side of class2:</p>
<pre class="brush: css;">
.class1 {
          width: 200px;
          background-color: #DEDEDE;
          float: right;
}
.class2 {
          width: 300px;
          background-color: #006699;
}
class3 {
          width: 500px;
          background-color: #009900;
}
</pre>
<a name="The+next+step"></a><h1>The next step</h1>
<p>Lets try a bit more advanced setup, where we will wrap some text around another element. To do this we have to place one element inside another like this:</p>
<pre class="brush: xml;">
&lt;div class=&quot;container&quot;&gt;
  &lt;div class=&quot;class1&quot;&gt; &lt;span class=&quot;class2&quot;&gt;This is the second class&lt;/span&gt;This is the first class This is the first class This is the first class This is the first class This is the first class This is the first class &lt;/div&gt;
  &lt;div class=&quot;class3&quot;&gt;This is the third class&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>To get the text in class wrapped around the class2 element, we have to set a float right on the class2. This makes it right aligned, and the text in class1 will then wrapped around it. </p>
<p>The CSS looks as follows:</p>
<pre class="brush: css;">
.class1 {
          width: 500px;
          background-color: #DEDEDE;
          float: left;
}
.class2 {
          width: 200px;
          background-color: #006699;
          float: right;
}
.class3 {
          width: 500px;
          background-color: #009900;
}
</pre>
<div class="container5">
<div class="class1"> <span class="class2">This is the second class</span>This is the first class This is the first class This is the first class This is the first class This is the first class This is the first class </div>
<div class="class3">This is the third class</div>
</div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-2002298237929711";
/* 468x15, oprettet 19-04-10 */
google_ad_slot = "2384876595";
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="Last+words"></a><h1>Last words</h1>
<p>That it. A very small and basic intro tutorial on the mysterious left and right floating. Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/howto-float-your-css/feed/</wfw:commentRss>
		<slash:comments>0</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[Java]]></category>
		<category><![CDATA[development]]></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&#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;">
&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;">
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>12</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[Java]]></category>
		<category><![CDATA[development]]></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&#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;">
...
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;">
...
            // 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;">
...
            // 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;">
...
            // 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>
<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;">
&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;">
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>2</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[Java]]></category>
		<category><![CDATA[development]]></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&#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;">
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;">
...
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;">
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;">
...
  // try opening the myfilename.txt
  try {
    // open the file for reading
    InputStream in = openFileInput(&quot;myfilename.txt&quot;);

    // if file the available for reading
    if (in) {
      // prepare the file for reading
      InputStreamReader input = new InputStreamReader(in);
      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
    in.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>0</slash:comments>
		</item>
		<item>
		<title>EasyJSCSS version 1.4 uploaded to wordpress.org</title>
		<link>http://huuah.com/easyjscss-version-1-4-uploaded-to-wordpress-org/</link>
		<comments>http://huuah.com/easyjscss-version-1-4-uploaded-to-wordpress-org/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 14:45:25 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[easyjscss]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=579</guid>
		<description><![CDATA[<p>I have updated the <a href="/easyjscss">EasyJSCSS </a>plugin for WordPress with some bugfixes and some backend improvements.</p>
<p>Version 1.4 is now available <a href="/easyjscss">here</a> or at <a href="http://wordpress.org/extend/plugins/easyjscss/">http://wordpress.org/extend/plugins/easyjscss/</a></p>
<p>Please post any comments regarding version 1.4 is this post.</p>
]]></description>
			<content:encoded><![CDATA[<p>I have updated the <a href="/easyjscss">EasyJSCSS </a>plugin for WordPress with some bugfixes and some backend improvements.</p>
<p>Version 1.4 is now available <a href="/easyjscss">here</a> or at <a href="http://wordpress.org/extend/plugins/easyjscss/">http://wordpress.org/extend/plugins/easyjscss/</a></p>
<p>Please post any comments regarding version 1.4 is this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/easyjscss-version-1-4-uploaded-to-wordpress-org/feed/</wfw:commentRss>
		<slash:comments>3</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[Java]]></category>
		<category><![CDATA[development]]></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>
<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&#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>
<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;">
&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;">
...
    &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;">
&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;">
...
&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;">
&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;">
  &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;">
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>5</slash:comments>
		</item>
		<item>
		<title>Basic jQuery div rotator</title>
		<link>http://huuah.com/basic-jquery-div-rotator/</link>
		<comments>http://huuah.com/basic-jquery-div-rotator/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 21:54:24 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=536</guid>
		<description><![CDATA[<p>So &#8211; how do one make a simple rotations function in jquery? There are many ways to do this, so I will just demonstrate one of them here:</p>
<a name="Example+code+for+the+jQuery+DIV+rotator%3A"></a>Example code for the jQuery DIV rotator:
<pre class="brush: xml;">
&#60;div class=&#34;&#34;&#62;
&#60;div class=&#34;focusitem active&#34;&#62;Item 1&#60;/div&#62;
&#60;div class=&#34;focusitem notactive&#34;&#62;Item 2&#60;/div&#62;
&#60;div</pre><p>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>So &#8211; how do one make a simple rotations function in jquery? There are many ways to do this, so I will just demonstrate one of them here:</p>
<a name="Example+code+for+the+jQuery+DIV+rotator%3A"></a><h1>Example code for the jQuery DIV rotator:</h1>
<pre class="brush: xml;">
&lt;div class=&quot;&quot;&gt;
&lt;div class=&quot;focusitem active&quot;&gt;Item 1&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 2&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 3&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 4&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>And this will output 4 divs as shown here:</p>
<div class="focusitem&nbsp;active">Item 1</div>
<div class="focusitem&nbsp;notactive">Item 2</div>
<div class="focusitem&nbsp;notactive">Item 3</div>
<div class="focusitem&nbsp;notactive">Item 4</div>
<p>Nothing exciting about this, really. So &#8211; lets add the forward and backward button for the shifting of visible divs.</p>
<a name="Make+the+items+rotate"></a><h1>Make the items rotate</h1>
<pre class="brush: xml;">
&lt;div class=&quot;goleft&quot;&gt;Go Left&lt;/div&gt;

&lt;div class=&quot;&quot;&gt;
&lt;div class=&quot;focusitem active&quot;&gt;Item 1&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 2&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 3&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 4&lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;goright&quot;&gt;Go Right&lt;/div&gt;
</pre>
<p>There is now added 2 buttons/divs/textsfield &#8211; a left one and a right one. All we have to do, is make the buttons change which div is visible. The easy way to do this, is by changing the class name of the div and with CSS control the visibility and format.</p>
<p>To register a click event on the left and right buttons, we have to use the click()-function in jQuery.</p>
<p>That can look like this:</p>
<p>Javascript:</p>
<pre class="brush: jscript;">
     // trigger the mouse click even
     $(&quot;.goleft&quot;).click( function(e) {
        // get the current active element
        var $active = $(&quot;.active&quot;);
        // get the previous element or, if no previous then get the last item in the focusitem-class.
        var $next = $active.prev().length ? $active.prev() : $(&quot;.focusitem:last&quot;);

        // set the visibility of the active and notactive classes.
        $active.removeClass('active');
        $active.addClass('notactive');
        $next.addClass('active');
        $next.removeClass('notactive');
    });
</pre>
<p>CSS:</p>
<pre class="brush: css;">
&lt;div class=&quot;focusitem active&quot;&gt;Item 1&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 2&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 3&lt;/div&gt;
&lt;div class=&quot;focusitem notactive&quot;&gt;Item 4&lt;/div&gt;
</pre>
<a name="Result%3A"></a><h1>Result:</h1>
<div class="goleft">Go Left</div>
<div class="">
<div class="focusitem active">Item 1</div>
<div class="focusitem notactive">Item 2</div>
<div class="focusitem notactive">Item 3</div>
<div class="focusitem notactive">Item 4</div>
</div>
<div class="goright">Go Right</div>
<div class="clear"></div>
<a name="How+it+works"></a><h1>How it works</h1>
<p>The jQuery rotation code gets activated as soon as a user clicks the buttons. It find the active element, and the next or previous element corresponding to which buttons is activated and the toggles the active and notactive classes on the focusitems.</p>
<p>Complete jQuery code:</p>
<pre class="brush: jscript;">
(document).ready(function() {

    $(&quot;.goleft&quot;).click( function(e) {
        var $active = $(&quot;.active&quot;);
        var $next = $active.prev().length ? $active.prev() : $(&quot;.focusitem:last&quot;);

        $active.removeClass('active');
        $active.addClass('notactive');
        $next.addClass('active');
        $next.removeClass('notactive');
    });

    $(&quot;.goright&quot;).click( function(e) {
        var $active = $(&quot;.active&quot;);
        var $next = $active.next().length ? $active.next() : $(&quot;.focusitem:first&quot;);

        $active.removeClass('active');
        $active.addClass('notactive');
        $next.addClass('active');
        $next.removeClass('notactive');
    });

});
</pre>
<p>Complete CSS for the above example:</p>
<pre class="brush: css;">
.active {
    display: block;
    width: 100px;
    float: left;
}
.notactive {
    display: none;
}

.goleft, .goright {
    cursor: pointer;
    width: 100px;
    float: left;
    border: 1px solid;
}
</pre>
<a name="Now+what%3F"></a><h1>Now what?</h1>
<p>For more fancy display that my example shows, try putting some images ind the focusitem and make some nice arrows for the go left and right buttons. The usability of the rotator will improve a lot, by making some easy layout adjustments. </p>
<p>Obvious expansions for this kind of rotator would be a more fancy shift/glide between active divs or perhaps loading each element with Ajax, but this is intensionally not covered in this post. </p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/basic-jquery-div-rotator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beginning SQL commands</title>
		<link>http://huuah.com/beginning-sql-commands/</link>
		<comments>http://huuah.com/beginning-sql-commands/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 15:14:24 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=503</guid>
		<description><![CDATA[<p>The first step to get an application (program, website etc.) to work against a database is knowing the 5 basic SQL commands. The following examples is based on MySQL, but should apply to every SQL-server. When mastering these 5 commands, you are off to a good start on SQL programming.&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>The first step to get an application (program, website etc.) to work against a database is knowing the 5 basic SQL commands. The following examples is based on MySQL, but should apply to every SQL-server. When mastering these 5 commands, you are off to a good start on SQL programming.</p>
<a name="Create+a+tabel"></a><h1>Create a tabel</h1>
<p>First we have to create a new database called &#8216;articles&#8217; and it will contain 2 fields &#8211; a numeric article id and text field for the article content. This is done with the <code>CREATE TABLE</code>-command:</p>
<pre class="brush: sql;">
CREATE TABLE `articles` (
`article_id` INT NOT NULL ,
`article_content` TEXT NOT NULL
)
</pre>
<p>Running the above code will create a database called <code>articles</code> with two fields <code>article_id</code> and <code>article_content</code>.</p>
<p>The database table is now ready for use.</p>
<a name="Inserting+into+a+table"></a><h1>Inserting into a table</h1>
<p>To insert data into to newly created database is done with the <code>INSERT</code>-command. When using the <code>INSERT</code>-command, you must specify which table the content should be inserted to and which fields to insert it into.</p>
<p>The <code>INSERT</code>-command is used with this syntax:</p>
<pre class="brush: sql;">INSERT INTO `table` (fields) VALUES (values);</pre>
<p><em>table</em>, <em>fields</em> and <em>values</em> must be replaced with the appropriate names, like this:</p>
<pre class="brush: sql;">INSERT INTO `articles` (`article_id`, `article_content`) VALUES ('1', 'First article...');</pre>
<p>This will insert an article to the <code>articles</code>-table, with an article id value of &#8217;1&#8242; and a content &#8216;First articles&#8230;&#8217;.</p>
<p>Let insert a couple more articles:</p>
<pre class="brush: sql;">INSERT INTO `articles` (`article_id`, `article_content`) VALUES ('2', 'Second article...');
INSERT INTO `articles` (`article_id`, `article_content`) VALUES ('3', 'Third article...');</pre>
<a name="Selecting+from+a+table"></a><h1>Selecting from a table</h1>
<p>The <code>articles</code>-table is now holding 3 articles with id 1, 2 and 3. To retrieve article information from the table, we have to use the <code>SELECT</code>-command. </p>
<p>Selecting content from the database is done by using this syntax:</p>
<pre class="brush: sql;">SELECT `field` FROM `table` WHERE search;</pre>
<p>Now &#8211; let select the article content for article no. 2:</p>
<pre class="brush: sql;">SELECT `article_content` FROM `articles` WHERE article_id='2';</pre>
<p>This will return a result set with the article content from article no 2.</p>
<p>Selecting from table can of course be must more advanced than this, but this will be covered in a later blog entry.</p>
<a name="Updating+a+table"></a><h1>Updating a table</h1>
<p>Now we know how to insert and select data in the database. At some point it&#8217;s often necessary to change the content of the tables. Changing values is done with the <code>UPDATE</code>-command.</p>
<pre class="brush: sql;">UPDATE `table` SET `field`=`value` WHERE search;</pre>
<p>So, to change the content of article no 3 from &#8216;Third article&#8217; to &#8216;yet another article&#8217; use a command like this:</p>
<pre class="brush: sql;">UPDATE `articles` SET `article_content`='yet another article' WHERE `article_id`='3'</pre>
<p>This will update the <code>article_content</code>-field to &#8216;yet another article&#8217; if the <code>article_id</code> is equal &#8217;3&#8242;.</p>
<a name="Delete+from+table"></a><h1>Delete from table</h1>
<p>The last command for now is the <code>DELETE</code>-command. This is used, when content in the database should be deleted and is used like this:</p>
<pre class="brush: sql;">DELETE FROM `table` WHERE search;</pre>
<p>The article no 1 is now going to be deleted and this is done with the following line:</p>
<pre class="brush: sql;">DELETE FROM `articles` WHERE `article_id`='1';</pre>
<p>That&#8217;s it. Article deleted.</p>
<a name="Ending"></a><h1>Ending</h1>
<p>The 5 basic SQL command has now been explained and I hope this will be useful when starting using databases. Every command can be expanded to be much more advanced than what I have shown here.</p>
<p>For further reading on how to create a basic <a href="http://huuah.com/a-simple-login-script-with-php-and-mysql/">login script with PHP and MySQL-database</a> &#8211; <a href="http://huuah.com/a-simple-login-script-with-php-and-mysql/">go here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/beginning-sql-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
