<?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>Thai Coding</title>
	<atom:link href="http://www.thaicoding.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thaicoding.net</link>
	<description>We love Programming</description>
	<lastBuildDate>Sun, 01 Jan 2012 06:45:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>เขียน Android การใช้งาน Single TouchScreen</title>
		<link>http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-android-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-single-touchscreen/</link>
		<comments>http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-android-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-single-touchscreen/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 06:38:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Mobile Programming]]></category>
		<category><![CDATA[Single TouchScreen]]></category>
		<category><![CDATA[จอสัมผัส]]></category>
		<category><![CDATA[มือถือ android]]></category>
		<category><![CDATA[เขียน android]]></category>
		<category><![CDATA[เขียนโปรแกรม android]]></category>
		<category><![CDATA[โปรแกรม android]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1316</guid>
		<description><![CDATA[Tweet ในมือถือ android หรือว่าพวก tablet นั้นความสามารถที่ต่างจากมือถือรุ่นเก่านั้น มีอยู่อย่างหนึ่งคือ หน้าจอแบบสัมผัสหรือที่เรียกว่า TouchScreen นั้นเอง แต่การ touch screen นั้นก็มีแบ่งออก 2 แบบคือ single touch screen กับ multi touch screen ซึ่งวันนี้ผมจะเอาตัวอย่างการใช้งานแบบ single touch screen มาให้ดูก่อน โดยครั้งนี้ผมจะใช้ api android 2.3.3 ซึ่งก็ลองอัพเวอร์ชั่นดูบ้างว่าโค้ดมีปัญหาอะไรรึเปล่าเพราะสังเกตว่ามือถือที่ออกมาหลังๆๆจะไล่ออก 2.3 กันซะส่วนใหญ่ยิ่งรุ่น top แพงๆๆก็ไป 4.0 ละ โดยผมได้สร้างโปรเจ็คที่ชื่อ THTouchScreen โดยใช้ api 2.3.3 มี min SDK Version 10 ครับโดยสร้างตามรูปเลยครับ เมื่อสร้างเสร็จเราก็เริ่มลงโค้ดกันเลยครับโดยการใช้งาน Touch Screen นั้นต้องทำการ implement [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b9%2580%25e0%25b8%2582%25e0%25b8%25b5%25e0%25b8%25a2%25e0%25b8%2599-android-%25e0%25b8%2581%25e0%25b8%25b2%25e0%25b8%25a3%25e0%25b9%2583%25e0%25b8%258a%25e0%25b9%2589%25e0%25b8%2587%25e0%25b8%25b2%25e0%25b8%2599-single-touchscreen%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-android-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-single-touchscreen/" data-count="vertical" data-via="" data-lang="de" data-text="เขียน Android การใช้งาน Single TouchScreen &raquo; Thai Coding #Single TouchScre [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p>ในมือถือ android หรือว่าพวก tablet นั้นความสามารถที่ต่างจากมือถือรุ่นเก่านั้น มีอยู่อย่างหนึ่งคือ หน้าจอแบบสัมผัสหรือที่เรียกว่า TouchScreen นั้นเอง แต่การ touch screen นั้นก็มีแบ่งออก 2 แบบคือ single touch screen กับ multi touch screen ซึ่งวันนี้ผมจะเอาตัวอย่างการใช้งานแบบ single touch screen มาให้ดูก่อน โดยครั้งนี้ผมจะใช้ api android 2.3.3 ซึ่งก็ลองอัพเวอร์ชั่นดูบ้างว่าโค้ดมีปัญหาอะไรรึเปล่าเพราะสังเกตว่ามือถือที่ออกมาหลังๆๆจะไล่ออก 2.3 กันซะส่วนใหญ่ยิ่งรุ่น top แพงๆๆก็ไป 4.0 ละ โดยผมได้สร้างโปรเจ็คที่ชื่อ THTouchScreen โดยใช้ api 2.3.3 มี min SDK Version 10 ครับโดยสร้างตามรูปเลยครับ</p>
<p><img alt="" src="http://www.thaicoding.net/wp-content/uploads/2012/01/1.jpg" /></p>
<p><span id="more-1316"></span></p>
<p><img alt="" src="http://www.thaicoding.net/wp-content/uploads/2012/01/2.jpg" /></p>
<p>เมื่อสร้างเสร็จเราก็เริ่มลงโค้ดกันเลยครับโดยการใช้งาน Touch Screen นั้นต้องทำการ implement OnTouchListener ซึ่งต้องทำการ import android.view.View.OnTouchListener; เข้ามา โดยตัวอย่างนี้จะมีการสร้าง TextView ขึ้นมาตัวหนึ่งเพื่อแสดงผลการ Touch Screen ที่เกิดขึ้น โดยใช้ String Builder เป็นตัวเก็บข้อมูลก่อนไปกำหนดค่าให้ TextView โดย String Builder ก็เป็นคลาสตัวช่วยในการใช้งานของ String อันหนึ่ง</p>
<p>โค้ดทั้งหมดครับ</p>
<pre class="brush: java">
package com.thaicoding.THTouchScreen;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;

public class THTouchScreen extends Activity implements OnTouchListener {
	StringBuilder builder = new StringBuilder();
	TextView textView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        textView = new TextView(this);
        textView.setText(&quot;Touch and drag (one finger)&quot;);
        textView.setOnTouchListener(this);
        setContentView(textView);
    }

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		builder.setLength(0);

		switch(event.getAction()){
		case MotionEvent.ACTION_DOWN:
			builder.append(&quot;down, &quot;);
			break;
		case MotionEvent.ACTION_MOVE:
			builder.append(&quot;move, &quot;);
			break;

		case MotionEvent.ACTION_CANCEL:
			builder.append(&quot;cancel, &quot;);
			break;
		case MotionEvent.ACTION_UP:
			builder.append(&quot;up, &quot;);
			break;
		}
		builder.append(event.getX());
		builder.append(&quot;,&quot;);
		builder.append(event.getY());
		String text = builder.toString();

		Log.d(&quot;THTouchTest&quot;, text);
		textView.setText(text);
		return true;
	}

}
</pre>
<p>เมื่อพิมพ์โค้ดเสร็จแล้วก็ลองรันดูครับแต่อย่าลืมถ้าคุณเลือก version ตามผมก็ต้องสร้าง emulation ตัวที่มี version ตรงกันนะครับ</p>
<p><img alt="" src="http://www.thaicoding.net/wp-content/uploads/2012/01/3.jpg" /></p>
<p>ผลลัพธ์การรันจะเห็นว่าจะมีการแสดงสถานะและตำแหน่งของจุดที่เราไปสัมผัสโดยในตัวอย่างนี้เป็นแบบ Single Touch Screen ซึ่งจะตรวจจับแค่จุดเดียวเท่านั้น ในสถานนะของ Touch Screen นั้นก็ประกอบด้วย Down คือการที่เรากดลงไปบนหน้าจอ , Up คือ การที่เอานิ้วออกจากหน้าจอ, Move คือการที่เราเอานิ้วไปสัมผัสบนหน้าจอแล้วเคลื่อนที่ , Cancel จะเป็นการยกเลิกใช้หน้าจอสัมผัส ซึ่งจากโค้ดตัวอย่างจะเห็นว่าใน method OnTouchListenerนั้นจะใช้ event.getAction() เพื่อหาว่าสถานะปัจจุบันของหน้าจอสัมผัสนั้นคืออะไรแล้วทำการเก็บข้อมูลเพื่อไปกำหนดค่าให้ TextView แล้วแสดงผลต่อไปส่วนตำแหน่งของจุดที่เราสัมผัสนั้นก็จะเก็บเป็นตำแหน่ง x, y ซึ่งใช้คำสั่ง event.getX() และ event.getY() โดยที่ event นั้นจะเป็นตัวแปรของ MotionEvent ครับ</p>
<p>นี้ก็เป็นตัวอย่างการใช้งาน Single TouchScreen ครับซึ่งเป็นโค้ดอย่างง่ายลองไล่ดูโค้ดนะครับเพื่อความเขาใจมากขึ้น และเนื่องในวันนี้เป็นวันปีใหม่ 2555 ขอให้ทุกท่านจงประสบแต่ความสำเร็จและความสุขนะครับจาก thaicoding.net</p>
<p><a href="http://www.mediafire.com/?x49bn1q44sgd4kp" rel="nofollow" target="_blank">Download SourceCode</a></p>

	Tags: <a href="http://www.thaicoding.net/tag/single-touchscreen/" title="Single TouchScreen" rel="tag">Single TouchScreen</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%88%e0%b8%ad%e0%b8%aa%e0%b8%b1%e0%b8%a1%e0%b8%9c%e0%b8%b1%e0%b8%aa/" title="จอสัมผัส" rel="tag">จอสัมผัส</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%a1%e0%b8%b7%e0%b8%ad%e0%b8%96%e0%b8%b7%e0%b8%ad-android/" title="มือถือ android" rel="tag">มือถือ android</a>, <a href="http://www.thaicoding.net/tag/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-android/" title="เขียน android" rel="tag">เขียน android</a>, <a href="http://www.thaicoding.net/tag/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%81%e0%b8%81%e0%b8%a3%e0%b8%a1-android/" title="เขียนโปรแกรม android" rel="tag">เขียนโปรแกรม android</a>, <a href="http://www.thaicoding.net/tag/%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%81%e0%b8%81%e0%b8%a3%e0%b8%a1-android/" title="โปรแกรม android" rel="tag">โปรแกรม android</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-android-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-single-touchscreen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>การสร้าง ActiveList แล้วเรียกใช้งาน class อื่น</title>
		<link>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87-activelist-%e0%b9%81%e0%b8%a5%e0%b9%89%e0%b8%a7%e0%b9%80%e0%b8%a3%e0%b8%b5%e0%b8%a2%e0%b8%81%e0%b9%83%e0%b8%8a%e0%b9%89/</link>
		<comments>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87-activelist-%e0%b9%81%e0%b8%a5%e0%b9%89%e0%b8%a7%e0%b9%80%e0%b8%a3%e0%b8%b5%e0%b8%a2%e0%b8%81%e0%b9%83%e0%b8%8a%e0%b9%89/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 15:32:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Mobile Programming]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1266</guid>
		<description><![CDATA[Tweet การสร้าง ActiveList แล้วเรียกใช้งาน class อื่น ในการพัฒนา android app นั้นเมื่อโปรแกรมมีการทำงานที่ซับซ้อนนั้น หลักการพื้นฐานของ oop ก็น่าจะเป็นการสร้าง class เพื่อที่จะสร้าง object ที่ทำงานต่างกันไป วันนี้หลังจากหายไปนานไม่ได้เขียนบทความเลย เอาตัวอย่างการสร้าง Active List เมื่อ เลือก list แล้วก็จะไปเรียกใช้งาน class ต่างๆที่มีอยู่ครับเราไปดูกันเลย หลังจากที่สร้างโปรเจ็คเสร็จแล้วให้เราทำการแก้ไขไฟล์หลัก ActiveList.java ให้ทำการ extends มาจาก ListActivity เพื่อที่เราจะทำการหน้าตาแบบ list ได้ โดยมีโค้ดดังนี้ package com.thaicoding.activelist; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; public class [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b8%2581%25e0%25b8%25b2%25e0%25b8%25a3%25e0%25b8%25aa%25e0%25b8%25a3%25e0%25b9%2589%25e0%25b8%25b2%25e0%25b8%2587-activelist-%25e0%25b9%2581%25e0%25b8%25a5%25e0%25b9%2589%25e0%25b8%25a7%25e0%25b9%2580%25e0%25b8%25a3%25e0%25b8%25b5%25e0%25b8%25a2%25e0%25b8%2581%25e0%25b9%2583%25e0%25b8%258a%25e0%25b9%2589%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87-activelist-%e0%b9%81%e0%b8%a5%e0%b9%89%e0%b8%a7%e0%b9%80%e0%b8%a3%e0%b8%b5%e0%b8%a2%e0%b8%81%e0%b9%83%e0%b8%8a%e0%b9%89/" data-count="vertical" data-via="" data-lang="de" data-text="การสร้าง ActiveList แล้วเรียกใช้งาน class อื่น &raquo; [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p><strong>การสร้าง ActiveList แล้วเรียกใช้งาน class อื่น</strong></p>
<p>ในการพัฒนา android app นั้นเมื่อโปรแกรมมีการทำงานที่ซับซ้อนนั้น หลักการพื้นฐานของ oop ก็น่าจะเป็นการสร้าง class เพื่อที่จะสร้าง object ที่ทำงานต่างกันไป วันนี้หลังจากหายไปนานไม่ได้เขียนบทความเลย เอาตัวอย่างการสร้าง Active List เมื่อ เลือก list แล้วก็จะไปเรียกใช้งาน class ต่างๆที่มีอยู่ครับเราไปดูกันเลย</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/12/1.jpg"><img class="alignnone size-full wp-image-1268" title="หัดเขียน android " src="http://www.thaicoding.net/wp-content/uploads/2011/12/1.jpg" alt="หัดเขียน android " width="544" height="370" /></a></p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/12/2.jpg"><img class="alignnone size-full wp-image-1269" title="หัดเขียน android" src="http://www.thaicoding.net/wp-content/uploads/2011/12/2.jpg" alt="หัดเขียน android" width="544" height="477" /></a></p>
<p>หลังจากที่สร้างโปรเจ็คเสร็จแล้วให้เราทำการแก้ไขไฟล์หลัก ActiveList.java ให้ทำการ extends มาจาก ListActivity<br />
<span id="more-1266"></span><br />
เพื่อที่เราจะทำการหน้าตาแบบ list ได้ โดยมีโค้ดดังนี้</p>
<pre class="brush: java">
package com.thaicoding.activelist;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ActiveList extends ListActivity {
    /** Called when the activity is first created. */
	String menu[] = {&quot;Helloword&quot;, &quot;Thaicoding&quot;};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setListAdapter(new ArrayAdapter&lt;String&gt;(this,
                android.R.layout.simple_list_item_1, menu));
    }
}
</pre>
<p>จากนั้นลองรันดูจะได้หน้าต่างแบบนี้</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/12/3.jpg"><img src="http://www.thaicoding.net/wp-content/uploads/2011/12/3.jpg" alt="" title="3" width="797" height="566" class="alignnone size-full wp-image-1275" /></a></p>
<p>ซึ่งเมนูเราสร้างมาจาก String array ที่ชื่อว่า menu นั้นเองส่วนรูปแบบ style นั้นก็จะกำหนดโดย android.R.layout.<em>simple_list_item_</em><em>1 </em>ซึ่งลองใช้แบบต่างๆดูได้ครับ ต่อมาเราจะมาสร้าง class ตามชื่อเมนูครับมีคลาสชื่อว่า? Helloword, Thaicoding</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/12/4.jpg"><img src="http://www.thaicoding.net/wp-content/uploads/2011/12/4.jpg" alt="" title="4" width="755" height="439" class="alignnone size-full wp-image-1276" /></a></p>
<p>โดยทั้ง 2 คลาสไม่มีอะไรมาให้มัน extends มาจาก? Activity โดยไม่มีการทำงานอะไรมากเพิ่งแค่สร้าง TextView จากนั้นก็จะแสดงผลออกทางหน้าจอซึ่งต่างกันเฉพาะคำเท่านั้น</p>
<p>โค้ดทั้ง 2 คลาส</p>
<pre class="brush: java">
package com.thaicoding.activelist;

import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;

public class Thaicoding extends Activity {

	TextView textView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        textView = new TextView(this);
        textView.setText(&quot;Thaicoding.net&quot;);
        setContentView(textView);
    }
}

package com.thaicoding.activelist;

import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;

public class Helloword extends Activity {
	TextView textView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        textView = new TextView(this);
        textView.setText(&quot;HelloWord&quot;);
        setContentView(textView);
    }
}
</pre>
<p>เมื่อสร้างคลาสทั้ง 2 แล้วเราก็มากำหนด action ให้กับคลาสหลักให้ทำการเพิ่ม onListItemClick โดยมีโค้ดทั้งหมดดังนี้</p>
<pre class="brush: java">
package com.thaicoding.activelist;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ActiveList extends ListActivity {
    /** Called when the activity is first created. */
	String menu[] = {&quot;Helloword&quot;, &quot;Thaicoding&quot;};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setListAdapter(new ArrayAdapter&lt;String&gt;(this,
                android.R.layout.simple_list_item_1, menu));
    }

    @Override
    protected void onListItemClick(ListView list, View view, int position,long id)
    {
        super.onListItemClick(list, view, position, id);
        String testName = menu[position];
        try {
            Class clazz = Class
                    .forName(&quot;com.thaicoding.activelist.&quot; + testName);
            Log.d(testName, testName);
            Intent intent = new Intent(this, clazz);
            startActivity(intent);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
</pre>
<p>หลักจากที่เราเขียนโค้ดเสร็จแล้วก็กำหนดสิทธิการรันของ class ในไฟล์ AndroidManifest.xml โดยเพิ่ม tag ใหม่จะได้ดังนี้</p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;com.thaicoding.activelist&quot;
      android:versionCode=&quot;1&quot;
      android:versionName=&quot;1.0&quot;&gt;
    &lt;uses-sdk android:minSdkVersion=&quot;8&quot; /&gt;

    &lt;application android:icon=&quot;@drawable/icon&quot; android:label=&quot;@string/app_name&quot;&gt;
        &lt;activity android:name=&quot;.ActiveList&quot;
                  android:label=&quot;@string/app_name&quot;&gt;
            &lt;intent-filter&gt;
                &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
                &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
        &lt;activity android:label=&quot;Helloword Test&quot;
		          android:name=&quot;.Helloword&quot;
			      android:configChanges=&quot;keyboard|keyboardHidden|orientation&quot; /&gt;
        &lt;activity android:label=&quot;Thaicoding Test&quot;
		          android:name=&quot;.Thaicoding&quot;
			      android:configChanges=&quot;keyboard|keyboardHidden|orientation&quot; /&gt;

    &lt;/application&gt;
&lt;/manifest&gt;
</pre>
<p>เมื่อเสร็จแล้วลองรันแล้วเลือกดูครับมันก็จะได้หน้าตาประมาณนี้ครับ</p>
<p>&nbsp;</p>
<p>หลักการสำคัญให้สังเกต onListItemClick ให้ดีครับจะมีการใช้งาน</p>
<p><span style="text-decoration: underline;">Class</span> clazz = Class.<em>forName</em>(&#8220;com.thaicoding.activelist.&#8221; + testName);</p>
<p>ซึ่ง testName นั้นจะเป็นชื่อ class ที่อยู่ในตัวแปรเมนูนั้นเอง ซึ่งในการใช้งานแบบนี้เราต้องดูเรื่องของ package ของภาษาจาวาให้ดีนะครับ หวังว่าจากตัวอย่างนี้จะทำให้หลายคนเอาไปประยุกต์ใช้งานได้นะครับ<br />
<a href="http://www.thaicoding.net/wp-content/uploads/2011/12/31.jpg"><img src="http://www.thaicoding.net/wp-content/uploads/2011/12/31.jpg" alt="" title="3" width="797" height="566" class="alignnone size-full wp-image-1281" /></a><br />
&nbsp;</p>
<p><a href="http://www.mediafire.com/?dvrlod4d51k67kv">Download SourceCode</a></p>
No tags for this post.]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87-activelist-%e0%b9%81%e0%b8%a5%e0%b9%89%e0%b8%a7%e0%b9%80%e0%b8%a3%e0%b8%b5%e0%b8%a2%e0%b8%81%e0%b9%83%e0%b8%8a%e0%b9%89/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>การสร้างสี่เหลี่ยมด้วย action script 3.0</title>
		<link>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87%e0%b8%aa%e0%b8%b5%e0%b9%88%e0%b9%80%e0%b8%ab%e0%b8%a5%e0%b8%b5%e0%b9%88%e0%b8%a2%e0%b8%a1%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-a/</link>
		<comments>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87%e0%b8%aa%e0%b8%b5%e0%b9%88%e0%b9%80%e0%b8%ab%e0%b8%a5%e0%b8%b5%e0%b9%88%e0%b8%a2%e0%b8%a1%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-a/#comments</comments>
		<pubDate>Sun, 13 Nov 2011 16:29:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[action script 3.0 หัด action script]]></category>
		<category><![CDATA[สอน action script]]></category>
		<category><![CDATA[สี่เหลี่ยม]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1259</guid>
		<description><![CDATA[Tweet หลังจากที่ adobe ประกาศว่าจะยกเลิกการพัฒนา flash player บนมือถือเล่นเอาคนที่อยู่ในวงการ flash คิดหนักกันพอสมควรมามันจะเป็นอย่างไรกันต่อไป แต่อย่างไรผมก็จะเขียนบทความต่อไปละกัน ครั้งนี้จะเป็นการสร้างสี่เหลี่ยมโดยใช้ action script ครับเรามาเริ่มกันเลยดีกว่า ขั้นแรกเราก็สร้างไฟล์ fla ที่เป็น action script 3.0 ก่อนครับ จากนั้นเมื่อเราสร้างไฟล์เสร็จแล้วให้ทำการคลิกที่ timeline แล้วก็คลิกขวาแบบในรูปเพื่อทำการเขียน action script จากนั้นก็เขียนโค้ดตามนี้ครับ import flash.display.MovieClip; var mc:MovieClip = new MovieClip(); mc.graphics.beginFill(0xFF0000); mc.graphics.drawRect(0,0,120,120); mc.graphics.endFill(); addChild(mc); เมื่อเขียนเสร็จก็ลองกด ctl+enter เพื่อทำการ test movie ดูครับจะเห็นว่ามีการสร้างสี่หลี่ยมสีแดงเกิดขึ้นครับ &#160; การทำงานของโค้ดก็คือ เรามีการสร้าง movie clip ขึ้นมา 1 ตัวเพราะการสร้างสีเหลี่ยมนั้นต้องอาศัย movie clip เป็นตัวสร้างเพราะ [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b8%2581%25e0%25b8%25b2%25e0%25b8%25a3%25e0%25b8%25aa%25e0%25b8%25a3%25e0%25b9%2589%25e0%25b8%25b2%25e0%25b8%2587%25e0%25b8%25aa%25e0%25b8%25b5%25e0%25b9%2588%25e0%25b9%2580%25e0%25b8%25ab%25e0%25b8%25a5%25e0%25b8%25b5%25e0%25b9%2588%25e0%25b8%25a2%25e0%25b8%25a1%25e0%25b8%2594%25e0%25b9%2589%25e0%25b8%25a7%25e0%25b8%25a2-a%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87%e0%b8%aa%e0%b8%b5%e0%b9%88%e0%b9%80%e0%b8%ab%e0%b8%a5%e0%b8%b5%e0%b9%88%e0%b8%a2%e0%b8%a1%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-a/" data-count="vertical" data-via="" data-lang="de" data-text="การสร้างสี่เหลี่ยมด้วย action script 3.0 &raquo; Thai Coding #ac [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p>หลังจากที่ adobe ประกาศว่าจะยกเลิกการพัฒนา flash player บนมือถือเล่นเอาคนที่อยู่ในวงการ flash คิดหนักกันพอสมควรมามันจะเป็นอย่างไรกันต่อไป แต่อย่างไรผมก็จะเขียนบทความต่อไปละกัน ครั้งนี้จะเป็นการสร้างสี่เหลี่ยมโดยใช้ action script ครับเรามาเริ่มกันเลยดีกว่า ขั้นแรกเราก็สร้างไฟล์ fla ที่เป็น action script 3.0 ก่อนครับ</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/11/11.jpg"><img class="alignnone size-full wp-image-1260" title="หัด action script" src="http://www.thaicoding.net/wp-content/uploads/2011/11/11.jpg" alt="หัด action script" width="528" height="381" /></a></p>
<p><span id="more-1259"></span>จากนั้นเมื่อเราสร้างไฟล์เสร็จแล้วให้ทำการคลิกที่ timeline แล้วก็คลิกขวาแบบในรูปเพื่อทำการเขียน action script</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/11/21.jpg"><img class="alignnone size-full wp-image-1261" title="หัด action script" src="http://www.thaicoding.net/wp-content/uploads/2011/11/21.jpg" alt="หัด action script" width="489" height="454" /></a></p>
<p>จากนั้นก็เขียนโค้ดตามนี้ครับ</p>
<pre class="brush: as3">

import flash.display.MovieClip;

var mc:MovieClip = new MovieClip();

mc.graphics.beginFill(0xFF0000);

mc.graphics.drawRect(0,0,120,120);

mc.graphics.endFill();

addChild(mc);
</pre>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/11/31.jpg"><img class="alignnone size-full wp-image-1262" title="หัด action script" src="http://www.thaicoding.net/wp-content/uploads/2011/11/31.jpg" alt="หัด action script" width="456" height="389" /></a></p>
<p>เมื่อเขียนเสร็จก็ลองกด ctl+enter เพื่อทำการ test movie ดูครับจะเห็นว่ามีการสร้างสี่หลี่ยมสีแดงเกิดขึ้นครับ</p>
<p>&nbsp;</p>
<p>การทำงานของโค้ดก็คือ เรามีการสร้าง movie clip ขึ้นมา 1 ตัวเพราะการสร้างสีเหลี่ยมนั้นต้องอาศัย movie clip เป็นตัวสร้างเพราะ movie clip นั้นมันจะเป็นตัว graphics ที่สามารถสร้างรูปร่างต่างๆ รวมไปถึงการแสดงภาพจากไฟล์ภาพด้วย เมื่อเราสร้าง movie clip ขึ้นมาแล้วจากนั้นเราก็เริ่มกำหนดสีให้มันด้วย method beginFill ซึ่งต้องใส่ค่าให้มัน โดยผมกำหนดสีเป็นสีแดงโดยการกำหนดสีนั้นต้องใส่เป็นเลขฐาน 16 ซึ่งเป็นค่าของสีครับจากนั้นเราก็สั่งให้มันทำการวาดสีเหลี่ยมโดยใช้ method drawRect เมื่อเราทำการวาดรูปต่างๆเสร็จแล้วเราก็ควรจบด้วย method endFill เพื่อเป็นการบอกว่าจบการวาดหรือกำหนดรูปร่างของ movie clip ครับ เมื่อเราทำการสร้างและกำหนดรูปร่างให้ movie clip แล้วเราก็ทำให้มันแสดงบนผลลัพธ์ของ stage โดยใช้คำสั่ง addChild() ครับ</p>
<p><a href="http://www.mediafire.com/?i6b67ppv326f4x2">Download SourceCode</a></p>

	Tags: <a href="http://www.thaicoding.net/tag/action-script-3-0-%e0%b8%ab%e0%b8%b1%e0%b8%94-action-script/" title="action script 3.0 หัด action script" rel="tag">action script 3.0 หัด action script</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%aa%e0%b8%ad%e0%b8%99-action-script/" title="สอน action script" rel="tag">สอน action script</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%aa%e0%b8%b5%e0%b9%88%e0%b9%80%e0%b8%ab%e0%b8%a5%e0%b8%b5%e0%b9%88%e0%b8%a2%e0%b8%a1/" title="สี่เหลี่ยม" rel="tag">สี่เหลี่ยม</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87%e0%b8%aa%e0%b8%b5%e0%b9%88%e0%b9%80%e0%b8%ab%e0%b8%a5%e0%b8%b5%e0%b9%88%e0%b8%a2%e0%b8%a1%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-a/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Action Script 3.0 การใช้งาน Timer</title>
		<link>http://www.thaicoding.net/action-script-3-0-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-timer/</link>
		<comments>http://www.thaicoding.net/action-script-3-0-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-timer/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 16:04:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[movie clip]]></category>
		<category><![CDATA[การใช้งาน Timer]]></category>
		<category><![CDATA[สอน ActionScript]]></category>
		<category><![CDATA[เริ่มเขียน actionscript]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1251</guid>
		<description><![CDATA[Tweet ในการเขียน action script นั้นเป็นการกำหนดเหตุการณ์และควบคุมเหตุการณ์ที่เกิดขึ้นในโปรแกรม ดังนั้นสิ่งหนึ่งที่ขาดไม่ได้ก็น่าจะเป็น timer เพราะมันสามารถทำสร้างหรือคงบคุมการทำงานตามเวลาที่เรากำหนดได้ ซึ่งมีประโยชน์มาก เรามาดูตัวอย่างการใช้ timer ใน action script กันเลย ขั้นแรกเราก็ทำการสร้างไฟล์ flash ตามรูปครับ จากนั้นไปในส่วน timeline เพื่อเปิด หน้าต่างเขียน actionขึ้นมาจากนั้นก็เขียนโค้ดตามนี้ครับ import flash.utils.Timer; import flash.events.TimerEvent; import flash.events.Event; var timeLine:Timer = new Timer(500); var mc:MovieClip = new MovieClip(); addChild(mc); var linex:int = 10; var liney:int = 10; timeLine.addEventListener(TimerEvent.TIMER, drawLine); timeLine.start(); function drawLine(e:Event) { trace(&#34;drawline&#34;); [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2Faction-script-3-0-%25e0%25b8%2581%25e0%25b8%25b2%25e0%25b8%25a3%25e0%25b9%2583%25e0%25b8%258a%25e0%25b9%2589%25e0%25b8%2587%25e0%25b8%25b2%25e0%25b8%2599-timer%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/action-script-3-0-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-timer/" data-count="vertical" data-via="" data-lang="de" data-text="Action Script 3.0 การใช้งาน Timer &raquo; Thai Coding #ActionScript #movie clip #การ [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p>ในการเขียน action script นั้นเป็นการกำหนดเหตุการณ์และควบคุมเหตุการณ์ที่เกิดขึ้นในโปรแกรม ดังนั้นสิ่งหนึ่งที่ขาดไม่ได้ก็น่าจะเป็น timer เพราะมันสามารถทำสร้างหรือคงบคุมการทำงานตามเวลาที่เรากำหนดได้ ซึ่งมีประโยชน์มาก</p>
<p>เรามาดูตัวอย่างการใช้ timer ใน action script กันเลย ขั้นแรกเราก็ทำการสร้างไฟล์ flash ตามรูปครับ</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/11/1.jpg"><img class="alignnone size-full wp-image-1252" title="action script" src="http://www.thaicoding.net/wp-content/uploads/2011/11/1.jpg" alt="action script" width="490" height="354" /></a></p>
<p><span id="more-1251"></span></p>
<p>จากนั้นไปในส่วน timeline เพื่อเปิด หน้าต่างเขียน actionขึ้นมาจากนั้นก็เขียนโค้ดตามนี้ครับ</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/11/2.jpg"><img class="alignnone size-full wp-image-1253" title="action script" src="http://www.thaicoding.net/wp-content/uploads/2011/11/2.jpg" alt="action script" width="394" height="449" /></a></p>
<pre class="brush: as3">

import flash.utils.Timer;

import flash.events.TimerEvent;

import flash.events.Event;

var timeLine:Timer = new Timer(500);

var mc:MovieClip = new MovieClip();

addChild(mc);

var linex:int = 10;

var liney:int = 10;

timeLine.addEventListener(TimerEvent.TIMER, drawLine);

timeLine.start();

function drawLine(e:Event)

{

trace(&quot;drawline&quot;);

mc.graphics.lineStyle(2, 0x990000, .75);

mc.graphics.moveTo(linex, liney);

linex = linex + 10;

liney = liney + 10;

mc.graphics.lineTo(linex,liney);

}
</pre>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/11/3.jpg"><img class="alignnone size-full wp-image-1254" title="action script" src="http://www.thaicoding.net/wp-content/uploads/2011/11/3.jpg" alt="action script" width="494" height="403" /></a></p>
<p>เมื่อกด ctrl + enter ก็ได้ผลลัพธ์ดังรูปโดยมันจะทำการวาดเส้นตรงตามค่า x, y เพิ่มขึ้นทุกๆ 500 ms ขั้นตอนในการทำงานของโค้ดเริ่มแรกเราต้องทำการ import package ที่เกี่ยวข้องกับ timer เข้ามาจากนั้นให้เราทำการสร้าง timer ขึ้นมา 1 ตัวโดยเรากำหนดเวลารอบโดยกำหนดไปใน constructor ตอนสร้าง object timer จากนั้นมีการสร้างตัวแปรแบบ movie clip ที่ชื่อว่า mc เพื่อทำการวาดรูปกราฟิกต่างๆ และมีการประกาศตัวแปรเพื่อเก็บตำแหน่ง x และ y จากนั้นเราก็ทำการ add movie clip mc ไปยัง stage โดยใช้คำสั่ง addChild จากนั้นเราก็ทำการใช้ event listener ให้กับ timer เพื่อให้ตัวแปร timeline จัดการเหตุการณ์ที่เกิดขึ้นโดยในการกำหนด addEventListener นั้นก็จะทำเมื่อ timer ครบทุกๆรอบนั้นคือครบทุกๆ 500 ms โดยจะให้ทำงานใน function drawLine โดยภายใน function นี้ก็จะมีการวาดเส้นตรงโดยให้ทำการ move ไปยังตำแหน่ง x และ y จากนั้นก็เพิ่มค่า x และ y แล้วทำการวาดเส้นตรงจากจุดที่มนอยู่ไปยังจุดใหม่ซึ่งเป็นจุดที่ค่า x และ y เพิ่มค่าไปแล้ว</p>
<p>&nbsp;</p>
<p><a href="http://www.mediafire.com/?2lask16dglnj32t">Download Source</a></p>

	Tags: <a href="http://www.thaicoding.net/tag/actionscript/" title="ActionScript" rel="tag">ActionScript</a>, <a href="http://www.thaicoding.net/tag/movie-clip/" title="movie clip" rel="tag">movie clip</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-timer/" title="การใช้งาน Timer" rel="tag">การใช้งาน Timer</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%aa%e0%b8%ad%e0%b8%99-actionscript/" title="สอน ActionScript" rel="tag">สอน ActionScript</a>, <a href="http://www.thaicoding.net/tag/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-actionscript/" title="เริ่มเขียน actionscript" rel="tag">เริ่มเขียน actionscript</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/action-script-3-0-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-timer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เขียนเกมส์ยามว่าง flash game fireball v1.0</title>
		<link>http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%80%e0%b8%81%e0%b8%a1%e0%b8%aa%e0%b9%8c%e0%b8%a2%e0%b8%b2%e0%b8%a1%e0%b8%a7%e0%b9%88%e0%b8%b2%e0%b8%87-flash-game-fireball-v1-0/</link>
		<comments>http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%80%e0%b8%81%e0%b8%a1%e0%b8%aa%e0%b9%8c%e0%b8%a2%e0%b8%b2%e0%b8%a1%e0%b8%a7%e0%b9%88%e0%b8%b2%e0%b8%87-flash-game-fireball-v1-0/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 16:07:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ทั่วไป]]></category>
		<category><![CDATA[action script]]></category>
		<category><![CDATA[fireball game]]></category>
		<category><![CDATA[flash game fireball]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1247</guid>
		<description><![CDATA[Tweet หลังจากที่ผมศึกษา actionscript มาสักพักก็เลยลองเขียนเกมส์ดูก็ปรากฎว่ามันสนุกดีเลย ว่าจะพัฒนาไปเรื่อยตามความรู้ที่มี นั้นก็คือถ้ามีความรู้เพิ่มขึ้นก็จะพัฒนาให้มันน่าเล่นมากกว่านี้และดีกว่านี้ครับ &#160; นี้เป็นวีดีโอที่ผมอัดไว้ เสียดายมันไม่มีเสียงเพราะ encode เสียงเครื่องผมมีปัญหาเวลาอัดแล้วอัพขึ้น youtube เลยมีปัญหาเรื่องเสียงครับ v1.0 นี้มีอะไรบ้าง หน้าตัวละครเปลี่ยนหน้าได้เวลาตีลูกบอล เสียงประกอบเวลาตีลูกบอลและเก็บดาว มีหน้า intro, game over และสามารถเล่นซ้ำได้ มีการแสดงผลคะแนน ส่วนรายละเอียดการเล่นก็คลิกที่เวลาตัวละครโดนลูกบอลเพื่อตีไปฝั่งตรงข้าม ถ้าลูกบอลเด่งไปยังเส้นหลังของคู่ต่อสู้เราก็จได้คะแนนใครได้ ห้าคะแนนก่อนชนะ ส่วนดาวนั้นจะเป็น item ทำให้ลูกที่เราตีไปไกลขึ้นซึ่งจะต้องเก็บให้มากๆๆ เพราะทุกครั้งที่เก็บได้ระยะทางการตีบอลจะเพิ่มขึ้นด้วย ส่วนใครอยากลองเล่นดูก็เลยได้ที่ลิงค์นี้ ครับ เล่นเกมส์ Tags: action script, fireball game, flash game fireball]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b9%2580%25e0%25b8%2582%25e0%25b8%25b5%25e0%25b8%25a2%25e0%25b8%2599%25e0%25b9%2580%25e0%25b8%2581%25e0%25b8%25a1%25e0%25b8%25aa%25e0%25b9%258c%25e0%25b8%25a2%25e0%25b8%25b2%25e0%25b8%25a1%25e0%25b8%25a7%25e0%25b9%2588%25e0%25b8%25b2%25e0%25b8%2587-flash-game-fireball-v1-0%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%80%e0%b8%81%e0%b8%a1%e0%b8%aa%e0%b9%8c%e0%b8%a2%e0%b8%b2%e0%b8%a1%e0%b8%a7%e0%b9%88%e0%b8%b2%e0%b8%87-flash-game-fireball-v1-0/" data-count="vertical" data-via="" data-lang="de" data-text="เขียนเกมส์ยามว่าง flash game fireball v1.0 &raquo; Thai Coding #action scr [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p>หลังจากที่ผมศึกษา actionscript มาสักพักก็เลยลองเขียนเกมส์ดูก็ปรากฎว่ามันสนุกดีเลย ว่าจะพัฒนาไปเรื่อยตามความรู้ที่มี นั้นก็คือถ้ามีความรู้เพิ่มขึ้นก็จะพัฒนาให้มันน่าเล่นมากกว่านี้และดีกว่านี้ครับ<br />
<object width="420" height="315" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/GamyAcF-8I4?version=3&amp;hl=en_US" /><param name="allowfullscreen" value="true" /><embed width="420" height="315" type="application/x-shockwave-flash" src="http://www.youtube.com/v/GamyAcF-8I4?version=3&amp;hl=en_US" allowFullScreen="true" allowscriptaccess="always" allowfullscreen="true" /></object></p>
<p>&nbsp;</p>
<p>นี้เป็นวีดีโอที่ผมอัดไว้ เสียดายมันไม่มีเสียงเพราะ encode เสียงเครื่องผมมีปัญหาเวลาอัดแล้วอัพขึ้น youtube เลยมีปัญหาเรื่องเสียงครับ</p>
<p>v1.0 นี้มีอะไรบ้าง</p>
<ul>
<li>หน้าตัวละครเปลี่ยนหน้าได้เวลาตีลูกบอล</li>
<li>เสียงประกอบเวลาตีลูกบอลและเก็บดาว</li>
<li>มีหน้า intro, game over และสามารถเล่นซ้ำได้</li>
<li>มีการแสดงผลคะแนน</li>
</ul>
<p>ส่วนรายละเอียดการเล่นก็คลิกที่เวลาตัวละครโดนลูกบอลเพื่อตีไปฝั่งตรงข้าม ถ้าลูกบอลเด่งไปยังเส้นหลังของคู่ต่อสู้เราก็จได้คะแนนใครได้ ห้าคะแนนก่อนชนะ ส่วนดาวนั้นจะเป็น item ทำให้ลูกที่เราตีไปไกลขึ้นซึ่งจะต้องเก็บให้มากๆๆ เพราะทุกครั้งที่เก็บได้ระยะทางการตีบอลจะเพิ่มขึ้นด้วย</p>
<p>ส่วนใครอยากลองเล่นดูก็เลยได้ที่ลิงค์นี้ ครับ<a title="เล่นเกมส์ fireball" href="http://thaicoding.net/games/fireballv1/game.html"> เล่นเกมส์</a></p>

	Tags: <a href="http://www.thaicoding.net/tag/action-script/" title="action script" rel="tag">action script</a>, <a href="http://www.thaicoding.net/tag/fireball-game/" title="fireball game" rel="tag">fireball game</a>, <a href="http://www.thaicoding.net/tag/flash-game-fireball/" title="flash game fireball" rel="tag">flash game fireball</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%80%e0%b8%81%e0%b8%a1%e0%b8%aa%e0%b9%8c%e0%b8%a2%e0%b8%b2%e0%b8%a1%e0%b8%a7%e0%b9%88%e0%b8%b2%e0%b8%87-flash-game-fireball-v1-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เริ่มเขียน actionscript ด้วย adobe flash cs 5.5</title>
		<link>http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-actionscript-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-adobe-flash-cs-5-5/</link>
		<comments>http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-actionscript-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-adobe-flash-cs-5-5/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 14:28:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[adobe flash cs 5.5]]></category>
		<category><![CDATA[สอน ActionScript]]></category>
		<category><![CDATA[เริ่มเขียน actionscript]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1223</guid>
		<description><![CDATA[Tweet เริ่มเขียน actionscript ด้วย adobe flash cs 5.5 วันนี้ผมเขียนบทความสำหรับผู้ที่เริ่มจะหัดเขียน actionscript หรือกำลังสนใจ ผมจะเขียนบทความที่เกี่ยวกับเขียน actionscript version 3.0 นะครับ โดยเราจำเป็นที่จะต้องหาโปรแกรม adobe flash cs 5.0 หรือ 5.5 ก็ได้ตามแต่ที่ท่านจะหามาลงในเครื่องได้นะครับ ขั้นแรกเราก็เปิดโปรแกรม flash มาจากนั้นเลือก new file แล้วมันจะมีหน้าต่างให้เลือกชนิดของไฟล์ที่เราจะสร้างโดย ผมเลือกเป็น ActionScript 3.0 เมื่อเราสร้างไฟล์เสร็จแล้วให้คลิกที่ tab timeline เพื่อจะไปยังหน้าต่าง script ซึ่งในการเขียน actionscript นั้นมันก็เขียนได้หลายรูปแบบ ทั้งเขียนบน stage เลย หรือจะแยกเป็นไฟล์คลาสหรือว่าจะเขียน script ใน movie clip ซึ่งในตัวอย่างนี้ผมจะเขียนบน stage ซึ่ง stage คืออะไรมันก็คือ stage [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b9%2580%25e0%25b8%25a3%25e0%25b8%25b4%25e0%25b9%2588%25e0%25b8%25a1%25e0%25b9%2580%25e0%25b8%2582%25e0%25b8%25b5%25e0%25b8%25a2%25e0%25b8%2599-actionscript-%25e0%25b8%2594%25e0%25b9%2589%25e0%25b8%25a7%25e0%25b8%25a2-adobe-flash-cs-5-5%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-actionscript-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-adobe-flash-cs-5-5/" data-count="vertical" data-via="" data-lang="de" data-text="เริ่มเขียน actionscript ด้วย adobe flash cs 5.5 &raquo; Thai Coding #ActionScrip [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p><strong>เริ่มเขียน actionscript ด้วย adobe flash cs 5.5</strong></p>
<p>วันนี้ผมเขียนบทความสำหรับผู้ที่เริ่มจะหัดเขียน actionscript หรือกำลังสนใจ ผมจะเขียนบทความที่เกี่ยวกับเขียน actionscript version 3.0 นะครับ โดยเราจำเป็นที่จะต้องหาโปรแกรม adobe flash cs 5.0 หรือ 5.5 ก็ได้ตามแต่ที่ท่านจะหามาลงในเครื่องได้นะครับ ขั้นแรกเราก็เปิดโปรแกรม flash มาจากนั้นเลือก new file แล้วมันจะมีหน้าต่างให้เลือกชนิดของไฟล์ที่เราจะสร้างโดย ผมเลือกเป็น ActionScript 3.0</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/10/1.jpg"><img class="alignnone size-full wp-image-1229" title="actionscript" src="http://www.thaicoding.net/wp-content/uploads/2011/10/1.jpg" alt="actionscript" width="503" height="362" /></a></p>
<p><span id="more-1223"></span>เมื่อเราสร้างไฟล์เสร็จแล้วให้คลิกที่ tab timeline เพื่อจะไปยังหน้าต่าง script ซึ่งในการเขียน actionscript นั้นมันก็เขียนได้หลายรูปแบบ ทั้งเขียนบน stage เลย หรือจะแยกเป็นไฟล์คลาสหรือว่าจะเขียน script ใน movie clip ซึ่งในตัวอย่างนี้ผมจะเขียนบน stage ซึ่ง stage คืออะไรมันก็คือ stage ในการแสดงผลของ flash ซึ่งจะแบ่งเป็น flame ตามที่เราต้องการซึ่งมันคล้ายๆกับโปรแกรมตัดต่อหนัง ที่มันจะมีวิดีโอหลักที่เราต้องใส่ effect ในวินาทีต่างๆนั้นเอง stage ก็เหมือนกันที่เราใส่เหตุการณ์ต่างๆ เอาละเรามาเขียน action script ?โดยให้ที่ timeline แล้วคลิกขวาที่เฟรมเหมือนในรูปจากนั้นก็เขียนโค้ดครับ</p>
<p>&nbsp;</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/10/2.jpg"><img class="alignnone size-full wp-image-1230" title="actionscript" src="http://www.thaicoding.net/wp-content/uploads/2011/10/2.jpg" alt="actionscript" width="511" height="498" /></a></p>
<p>&nbsp;</p>
<pre class="brush: as3">
import flash.text.TextField;

var textmessage:TextField = new TextField();

textmessage.text = &quot;Thaicoding.net&quot;;

addChild(textmessage);

trace(&quot;Thaicoding.net&quot;);
</pre>
<p>เมื่อเราเขียนโค้ดเสร็จแล้วให้ลองรันโปรแกรมดูโดยกด ctr+enter ครับแล้วจะได้ผลลัพธ์ดังรูป</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/10/3.jpg"><img class="alignnone size-full wp-image-1231" title="actionscript" src="http://www.thaicoding.net/wp-content/uploads/2011/10/3.jpg" alt="actionscript" width="443" height="575" /></a></p>
<p>&nbsp;</p>
<p>โดยโปรแกรมนี้มันได้ทำการสร้าง TextField ขึ้นมา จากนั้นกำหนดให้มันมีข้อความว่า Thaicoding.net จากนั้นเราก็ทำให้มันไปอยู่ใน stage โดยใช้คำสั่ง addChild() นั้นเองซึ่งใน action script นี้หากเราจะต้องการสร้างหรือใช้ control ตัวใดเราต้องทำการ import library ของ control ตัวนั้นเข้ามา แต่ส่วนมาโปรแกรม adobe flash มันจะทำการ import อัตโนมัติให้อยู่แล้วถ้าคุณไม่ไปปรับค่าอะไร ส่วนคำสั่ง trace นั้นมันใช้แสดงข้อความออกทางหน้าต่าง output ซึ่งมันมีประโยชน์ในการ debug โปรแกรมอย่างมากครับ</p>
<p>&nbsp;</p>
<p><a href="http://www.mediafire.com/?i6z3646ic4359gh">Download SourceCode</a></p>

	Tags: <a href="http://www.thaicoding.net/tag/actionscript/" title="ActionScript" rel="tag">ActionScript</a>, <a href="http://www.thaicoding.net/tag/adobe-flash-cs-5-5/" title="adobe flash cs 5.5" rel="tag">adobe flash cs 5.5</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%aa%e0%b8%ad%e0%b8%99-actionscript/" title="สอน ActionScript" rel="tag">สอน ActionScript</a>, <a href="http://www.thaicoding.net/tag/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-actionscript/" title="เริ่มเขียน actionscript" rel="tag">เริ่มเขียน actionscript</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-actionscript-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-adobe-flash-cs-5-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เพิ่มหมวดหมู่ใหม่ ActionScript</title>
		<link>http://www.thaicoding.net/%e0%b9%80%e0%b8%9e%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%ab%e0%b8%a1%e0%b8%a7%e0%b8%94%e0%b8%ab%e0%b8%a1%e0%b8%b9%e0%b9%88%e0%b9%83%e0%b8%ab%e0%b8%a1%e0%b9%88-actionscript/</link>
		<comments>http://www.thaicoding.net/%e0%b9%80%e0%b8%9e%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%ab%e0%b8%a1%e0%b8%a7%e0%b8%94%e0%b8%ab%e0%b8%a1%e0%b8%b9%e0%b9%88%e0%b9%83%e0%b8%ab%e0%b8%a1%e0%b9%88-actionscript/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 14:06:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[ทั่วไป]]></category>
		<category><![CDATA[game ActionScript]]></category>
		<category><![CDATA[สอน ActionScript]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1208</guid>
		<description><![CDATA[Tweet หลายคนที่ติดตามบล็อคของผม thaicoding.net คงสงสัยว่าทำไมผมไม่เขียนบทความใหม่เลย ผมไม่ได้หายไปไหนหรอกแค่ไปหัดวิชามาใหม่ครับ นั่งอ่านหนังสือแล้วก็หัดได้แบบงูๆปลามาอีก 1 วิชา มันก็คือ actionscript ของ adobe นั้นเอง ผมเขียนกับ adobe flash cs5. ครับแล้วต่อจากนี้บล็อคของผมจะมีเรื่องหาเพิ่มเข้ามาอีก 1 หมวดหมู่? แต่ว่าบ้างหมวดหมู่ยังมีเนื้อหาน้อยอยู่เลย อันนี้ก็ต้องขึ้นกับอารมณ์ผมครับว่าช่วงไหนอยากศึกษาอะไร เลยขออภัยมานะที่นี้ครับ และด้วยการเพิ่มหมวดหมู่ใหม่อย่ actionscript เลยเอาเกมส์แบบกากๆ ฝีมือผมมาโพสให้ดูครับ game ตัวเกมส์อาจจะมีบักอยู่เยอะครับเนื่องจากทำครั้งแรกในชีวิต ยิ่งถ้าหากเครื่องท่านมีโปรแกรมดาวโหลดที่ดักจับ mp3 แล้วมันจะยิ่ง errors เพราะมันเล่นไฟล์เสียงไม่ได้ครับ แต่ถ้าท่านไม่ได้ลง flash player เวอร์ชัน debug คงไม่มีปัญหาเท่าไรครับ Tags: ActionScript, game ActionScript, สอน ActionScript]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b9%2580%25e0%25b8%259e%25e0%25b8%25b4%25e0%25b9%2588%25e0%25b8%25a1%25e0%25b8%25ab%25e0%25b8%25a1%25e0%25b8%25a7%25e0%25b8%2594%25e0%25b8%25ab%25e0%25b8%25a1%25e0%25b8%25b9%25e0%25b9%2588%25e0%25b9%2583%25e0%25b8%25ab%25e0%25b8%25a1%25e0%25b9%2588-actionscript%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b9%80%e0%b8%9e%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%ab%e0%b8%a1%e0%b8%a7%e0%b8%94%e0%b8%ab%e0%b8%a1%e0%b8%b9%e0%b9%88%e0%b9%83%e0%b8%ab%e0%b8%a1%e0%b9%88-actionscript/" data-count="vertical" data-via="" data-lang="de" data-text="เพิ่มหมวดหมู่ใหม่ ActionScript &raquo; Thai Coding #ActionScript #game Act [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p>หลายคนที่ติดตามบล็อคของผม thaicoding.net คงสงสัยว่าทำไมผมไม่เขียนบทความใหม่เลย ผมไม่ได้หายไปไหนหรอกแค่ไปหัดวิชามาใหม่ครับ นั่งอ่านหนังสือแล้วก็หัดได้แบบงูๆปลามาอีก 1 วิชา มันก็คือ <a title="actionscript " href="http://www.thaicoding.net/category/actionscript/">actionscript</a> ของ adobe นั้นเอง ผมเขียนกับ adobe flash cs5. ครับแล้วต่อจากนี้บล็อคของผมจะมีเรื่องหาเพิ่มเข้ามาอีก 1 หมวดหมู่? แต่ว่าบ้างหมวดหมู่ยังมีเนื้อหาน้อยอยู่เลย อันนี้ก็ต้องขึ้นกับอารมณ์ผมครับว่าช่วงไหนอยากศึกษาอะไร เลยขออภัยมานะที่นี้ครับ และด้วยการเพิ่มหมวดหมู่ใหม่อย่ actionscript เลยเอาเกมส์แบบกากๆ ฝีมือผมมาโพสให้ดูครับ</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/10/game1.swf">game</a></p>
<p>ตัวเกมส์อาจจะมีบักอยู่เยอะครับเนื่องจากทำครั้งแรกในชีวิต ยิ่งถ้าหากเครื่องท่านมีโปรแกรมดาวโหลดที่ดักจับ mp3 แล้วมันจะยิ่ง errors เพราะมันเล่นไฟล์เสียงไม่ได้ครับ แต่ถ้าท่านไม่ได้ลง flash player เวอร์ชัน debug คงไม่มีปัญหาเท่าไรครับ</p>

	Tags: <a href="http://www.thaicoding.net/tag/actionscript/" title="ActionScript" rel="tag">ActionScript</a>, <a href="http://www.thaicoding.net/tag/game-actionscript/" title="game ActionScript" rel="tag">game ActionScript</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%aa%e0%b8%ad%e0%b8%99-actionscript/" title="สอน ActionScript" rel="tag">สอน ActionScript</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b9%80%e0%b8%9e%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%ab%e0%b8%a1%e0%b8%a7%e0%b8%94%e0%b8%ab%e0%b8%a1%e0%b8%b9%e0%b9%88%e0%b9%83%e0%b8%ab%e0%b8%a1%e0%b9%88-actionscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>การเปลี่ยนฉากหรือ intent ใน android</title>
		<link>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%80%e0%b8%9b%e0%b8%a5%e0%b8%b5%e0%b9%88%e0%b8%a2%e0%b8%99%e0%b8%89%e0%b8%b2%e0%b8%81%e0%b8%ab%e0%b8%a3%e0%b8%b7%e0%b8%ad-intent-%e0%b9%83%e0%b8%99-android/</link>
		<comments>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%80%e0%b8%9b%e0%b8%a5%e0%b8%b5%e0%b9%88%e0%b8%a2%e0%b8%99%e0%b8%89%e0%b8%b2%e0%b8%81%e0%b8%ab%e0%b8%a3%e0%b8%b7%e0%b8%ad-intent-%e0%b9%83%e0%b8%99-android/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 16:27:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Mobile Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[สอน android]]></category>
		<category><![CDATA[หัดเขียน android]]></category>
		<category><![CDATA[เขียนโปรแกรม android]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1196</guid>
		<description><![CDATA[Tweet การเปลี่ยนฉากหรือ intent ใน android หายไปนานกลับการเขียนบทความ จนเรียกว่าแทบจะไม่มีใครเข้าเว็บอยู่แล้วเพราะไม่มีอะไรใหม่ๆเลย ก็มันไม่ว่างจริงๆเลยไม่ได้เขียน การเขียนบทความที่เป็นแนว tutorial นั้นมันต้องใช้เวลาในการเขียนแต่ละบทความต้องศึกษาแล้วก็ทดลองก่อนว่ามันได้ตามนั้นหรือไม่ เอาละมาครั้งนี้ก็เขียนบทความ android กันต่อเหตุที่ผลเลือกเขียนบทความ android เพราะตอนนี้มันกำลังเป็นที่นิยม เลยขอเป็นพลังเล็กน้อยที่ทำให้เยาวชน มีแหล่งความรู้ในการพัฒนา software บทความนี้จะเป็นการเปลี่ยนฉากในโปรแกรมหรือที่เรียกว่า intent ใน การเขียนโปรแกรม android นั้นเอง ขั้นแรกก็สร้าง project ใหม่ขึ้นมา โดยผมจะตั้งชื่อว่า THCIntent ตามรูปครับ เมื่อสร้าง project เสร็จแล้วให้ทำการสร้าง string และสร้าง button รวมไปถึงการสร้างหน้าที่จะสลับระหว่างหน้าหลักโดยให้ทำการสร้าง string ในไฟล์ string.xml โดยเพิ่มอีก 2 string คือ &#60;string name=&#34;main_intent&#34;&#62;Main Menu&#60;/string&#62; &#60;string name=&#34;swap_intent&#34;&#62;Swap Menu&#60;/string&#62; เมื่อสร้าง string เสร็จแล้วให้ทำการเพิ่มปุ่มในไฟล์ xml [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b8%2581%25e0%25b8%25b2%25e0%25b8%25a3%25e0%25b9%2580%25e0%25b8%259b%25e0%25b8%25a5%25e0%25b8%25b5%25e0%25b9%2588%25e0%25b8%25a2%25e0%25b8%2599%25e0%25b8%2589%25e0%25b8%25b2%25e0%25b8%2581%25e0%25b8%25ab%25e0%25b8%25a3%25e0%25b8%25b7%25e0%25b8%25ad-intent-%25e0%25b9%2583%25e0%25b8%2599-android%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%80%e0%b8%9b%e0%b8%a5%e0%b8%b5%e0%b9%88%e0%b8%a2%e0%b8%99%e0%b8%89%e0%b8%b2%e0%b8%81%e0%b8%ab%e0%b8%a3%e0%b8%b7%e0%b8%ad-intent-%e0%b9%83%e0%b8%99-android/" data-count="vertical" data-via="" data-lang="de" data-text="การเปลี่ยนฉากหรือ intent ใน android &raquo; Thai Coding #android #ส [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p><strong>การเปลี่ยนฉากหรือ intent ใน android</strong></p>
<p>หายไปนานกลับการเขียนบทความ จนเรียกว่าแทบจะไม่มีใครเข้าเว็บอยู่แล้วเพราะไม่มีอะไรใหม่ๆเลย ก็มันไม่ว่างจริงๆเลยไม่ได้เขียน การเขียนบทความที่เป็นแนว tutorial นั้นมันต้องใช้เวลาในการเขียนแต่ละบทความต้องศึกษาแล้วก็ทดลองก่อนว่ามันได้ตามนั้นหรือไม่ เอาละมาครั้งนี้ก็เขียนบทความ android กันต่อเหตุที่ผลเลือกเขียนบทความ android เพราะตอนนี้มันกำลังเป็นที่นิยม เลยขอเป็นพลังเล็กน้อยที่ทำให้เยาวชน มีแหล่งความรู้ในการพัฒนา software</p>
<p>บทความนี้จะเป็นการเปลี่ยนฉากในโปรแกรมหรือที่เรียกว่า intent ใน การเขียนโปรแกรม android นั้นเอง<span id="more-1196"></span></p>
<p>ขั้นแรกก็สร้าง project ใหม่ขึ้นมา โดยผมจะตั้งชื่อว่า THCIntent ตามรูปครับ</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/10/android1.jpg"><img class="alignnone size-full wp-image-1197" title="android" src="http://www.thaicoding.net/wp-content/uploads/2011/10/android1.jpg" alt="android" width="445" height="465" /></a></p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/10/android2.jpg"><img class="alignnone size-full wp-image-1198" title="android" src="http://www.thaicoding.net/wp-content/uploads/2011/10/android2.jpg" alt="android" width="500" height="274" /></a></p>
<p>เมื่อสร้าง project เสร็จแล้วให้ทำการสร้าง string และสร้าง button รวมไปถึงการสร้างหน้าที่จะสลับระหว่างหน้าหลักโดยให้ทำการสร้าง string ในไฟล์ string.xml โดยเพิ่มอีก 2 string คือ</p>
<pre class="brush: java">
    &lt;string name=&quot;main_intent&quot;&gt;Main Menu&lt;/string&gt;
    &lt;string name=&quot;swap_intent&quot;&gt;Swap Menu&lt;/string&gt;
</pre>
<p>เมื่อสร้าง string เสร็จแล้วให้ทำการเพิ่มปุ่มในไฟล์ xml ที่กำหนดหน้าหลักในไฟล์ main.xml ดังนี้</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;
    android:background=&quot;@color/yellow&quot;
    &gt;
&lt;TextView
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:text=&quot;@string/hello&quot;
    /&gt;
 &lt;Button
   	android:id=&quot;@+id/mainbutton&quot;
   	android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
   	android:text=&quot;@string/main_intent&quot;
    /&gt;
&lt;/LinearLayout&gt;
</pre>
<p>ต่อจากนั้นก็สร้างไฟล์ใหม่เพื่อหน้าที่จะสลับ โดยผมจะตั้งชื่อว่า swapintent.xml โดยจะอยู่ใน directory layout โดยถ้าให้ง่ายก็ก็อปโค้ดจาก main.xml ไปแล้วก็เปลี่ยนค่าของ button มาส่วน</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/10/newclass.jpg"><img class="alignnone size-full wp-image-1199" title="newclass" src="http://www.thaicoding.net/wp-content/uploads/2011/10/newclass.jpg" alt="newclass" width="303" height="192" /></a></p>
<pre class="brush: xml">
 &lt;Button
   	android:id=&quot;@+id/swapbutton&quot;
   	android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
   	android:text=&quot;@string/swap_intent&quot;
    /&gt;
</pre>
<p>แล้วก็ในส่วนของ background color ด้วยครับ</p>
<p>android:background=?@color/red?</p>
<p>เพื่อให้สังเกตการณ์เปลี่ยนฉากหรือ intent นั้นผมจะกำหนดสีให้แต่ละหน้าเพื่อที่จะได้เห็นผลชัดเจนโดยที่จะไปสร้างไฟล์เพื่อเก็บค่าสีใน value ไฟล์ชื่อว่า colors.xml โดยเพิ่มโค้ดดังนี้</p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;resources&gt;
	&lt;color name=&quot;red&quot;&gt;#FFFF0000&lt;/color&gt;
	&lt;color name=&quot;yellow&quot;&gt;#EEEE00&lt;/color&gt;
&lt;/resources&gt;
</pre>
<p>ต่อมาก็เขียนโค้ดจาวาในไฟล์โค้ดหน้าหลักและหน้ารองโดยในหน้าหลักหรือว่า class หลักก็มีโค้ดต่อไปนี้</p>
<pre class="brush: java">
package org.thaicoding.thcintent;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.content.Intent;

public class THCIntent extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button swapButton = (Button)findViewById(R.id.mainbutton);

        swapButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(THCIntent.this,SwapIntent.class);
				startActivity(intent);
			}
		});
    }
}
</pre>
<p>ส่วน class ที่ทำหน้าที่ในหน้ารองคือ SwapIntent.java มีโค้ดดังนี้</p>
<pre class="brush: java">
package org.thaicoding.thcintent;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class SwapIntent extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 setContentView(R.layout.swapintent);

		 Button mainButton = (Button)findViewById(R.id.swapbutton);
		 mainButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
	 }
}
</pre>
<p>หลักจากเขียนโค้ดเสร็จแล้วเราก็มากำหนด Activity ที่อนุญาตให้ทำงานในไฟล์ AndroidManifest.xml โดยให้เพิ่ม activity ที่อนุญาตขึ้นมาอีก 1 อันคือ SwapIntent นั้นเองโดยมีการเพิ่มโค้ดแล้วจะได้ดังนี้</p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;org.thaicoding.thcintent&quot;
      android:versionCode=&quot;1&quot;
      android:versionName=&quot;1.0&quot;&gt;
    &lt;uses-sdk android:minSdkVersion=&quot;8&quot; /&gt;

    &lt;application android:icon=&quot;@drawable/icon&quot; android:label=&quot;@string/app_name&quot;&gt;
        &lt;activity android:name=&quot;.THCIntent&quot;
                  android:label=&quot;@string/app_name&quot;&gt;
            &lt;intent-filter&gt;
                &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
                &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
        &lt;activity android:name=&quot;.SwapIntent&quot;
                  android:label=&quot;@string/app_name&quot; /&gt;
    &lt;/application&gt;
&lt;/manifest&gt;
</pre>
<p>หลังจากเพิ่มโค้ดเสร็จหมดแล้วก็ลองรันโปรแกรมดูครับ</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/10/result.jpg"><img class="alignnone size-full wp-image-1200" title="result" src="http://www.thaicoding.net/wp-content/uploads/2011/10/result.jpg" alt="" width="562" height="399" /></a></p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/10/result2.jpg"><img class="alignnone size-full wp-image-1201" title="android" src="http://www.thaicoding.net/wp-content/uploads/2011/10/result2.jpg" alt="android" width="578" height="410" /></a></p>
<p>จะเห็นว่าเมื่อรันโปรแกรมเวลากดปุ่มมันจะสลับหน้าต่างกันซึ่ง จากในโค้ดหน้าต่างมันใช้คนละ class กันครับซึ่งทำให้เห็นว่าหากเรามีการให้ application เปลี่ยนหน้าต่างเมนูแล้วละก็ให้ class แต่ละอันรับผิดชอบการทำงานไปเลยทำให้ application เรามีความซับซ้อนมากขึ้นครับ สิ่งที่จะให้สังเกตก็คือ</p>
<p>Intent intent = <strong>new</strong> Intent(THCIntent.<strong>this</strong>,SwapIntent.<strong>class</strong>);</p>
<p>startActivity(intent);</p>
<p>คำสั่งนี้จะเป็นการเรียกใช้ intent มาใช้งานซึ่งจะมีการกำหนด intent จะมีการกำหนด component หรือ class ที่เป็นปลายทางขึ้น ซึ่งเมื่อเราใช้คำสั่ง startActivity(intent); จึงทำให้เราไปเรียกใช้งาน class SwapIntent นั้นเองโดยภายใน คลาส SwapIntent นั้นก็มีโค้ดคล้ายกับโค้ดหลักอยู่แล้วต่างกันที่ setContentView(R.layout.<em>swapintent</em>);</p>
<p>ซึ่งคำสั่ง Intent นั้นทำให้โปรแกรมไปทำงานใน class SwapIntent แทนแล้ว คลาส SwapIntent นี้ก็มีการเรียกให้เปลี่ยนหน้าเมนูอีกจึงเป็นเหตุเมื่อเราเปลี่ยน class ทำงานหน้าต่างก็เปลี่ยนไปนั้นเอง แล้วเมื่อ class SwapIntent นั้นมีการสร้างปุ่มซึ่งเมื่อคลิกมันจะใช้คำสั่ง finish ทำให้โปรแกรมกลับไปทำงานใน class เดิมที่เรียกมานั้นเอง</p>
<p>หากใครไม่เข้าวิธีการใส่ event ให้กับปุ่มหรืองงอะไรท่านสามารถไปดูได้ในหมวดหมู่<a title="Mobile Programming" href="http://www.thaicoding.net/category/mobile-programming/"> mobile programming</a> ได้ครับ</p>
<p>&nbsp;</p>
<p><a href="http://www.mediafire.com/download.php?a3b9g80ahu93f2k">Download Sourcecode</a></p>

	Tags: <a href="http://www.thaicoding.net/tag/android/" title="android" rel="tag">android</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%aa%e0%b8%ad%e0%b8%99-android/" title="สอน android" rel="tag">สอน android</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%ab%e0%b8%b1%e0%b8%94%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-android/" title="หัดเขียน android" rel="tag">หัดเขียน android</a>, <a href="http://www.thaicoding.net/tag/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%81%e0%b8%81%e0%b8%a3%e0%b8%a1-android/" title="เขียนโปรแกรม android" rel="tag">เขียนโปรแกรม android</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%80%e0%b8%9b%e0%b8%a5%e0%b8%b5%e0%b9%88%e0%b8%a2%e0%b8%99%e0%b8%89%e0%b8%b2%e0%b8%81%e0%b8%ab%e0%b8%a3%e0%b8%b7%e0%b8%ad-intent-%e0%b9%83%e0%b8%99-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เขียนโปรแกรม android : Web Viewer</title>
		<link>http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%81%e0%b8%81%e0%b8%a3%e0%b8%a1-android-web-viewer/</link>
		<comments>http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%81%e0%b8%81%e0%b8%a3%e0%b8%a1-android-web-viewer/#comments</comments>
		<pubDate>Sun, 11 Sep 2011 15:14:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Mobile Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[Web Viewer]]></category>
		<category><![CDATA[หัดเขียน android]]></category>
		<category><![CDATA[เขียนโปรแกรม android]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1185</guid>
		<description><![CDATA[Tweet เขียนโปรแกรม android : Web Viewer หลังจากหายไปนานกลับบทความที่เกี่ยวการพัฒนาโปรแกรมใน android ผมก็กลับมาเขียนอีกครั้ง บ้างครั้งก็น้อยใจตัวเองที่ไม่มีปัญหาจะซื้อ smart phone ที่มีระบบปฏิบัติการ android กับเค้าซะทีจะได้ตั้งหน้าตั้งตาพัฒนา android application ?แล้วมันจำเป็นที่จะต้องมีมือถือ android ด้วยหรอ ? คำตอบก็คือคำว่าใช้ครับ เพราะลำพัง simulator ที่ติดมาใน eclipse นั้นไม่พอหรอกไหนจะลอง test โปรแกรมไหนจะ ทดสอบระบบ touch screen เพราะระบบ simulator นั้นไม่สามารถจะจำลองระบบสัมผัสได้นั้นเอง เอาเถอะไหนๆก็ไหนๆเขียนกันต่อไป บทความนี้จะเป็นเนื้อหาเกี่ยวกับ web viewer ซึ่งเป็นตัวที่ช่วยให้โปรแกรมเราเข้าเว็บได้ซึ่ง บ้างครั้งเราไม่ต้องการจะใช้ web browser ที่มากับมือถือก็สามารถใช้ web viewer ได้ซึ่งมันสามารถไปพัฒนาต่อเพื่อจะดึงค่าและกำหนดการแสดงผลของเว็บได้นะครับ &#160; &#160; หลังจากได้สร้าง project แล้วสิ่งแรกที่ต้องทำการกำหนดคือหน้าตาของโปรแกรมซึ่งไปกำหนดในไฟล์ main.xml ซึ่งอยู่ใน res/layout/main.xml [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b9%2580%25e0%25b8%2582%25e0%25b8%25b5%25e0%25b8%25a2%25e0%25b8%2599%25e0%25b9%2582%25e0%25b8%259b%25e0%25b8%25a3%25e0%25b9%2581%25e0%25b8%2581%25e0%25b8%25a3%25e0%25b8%25a1-android-web-viewer%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%81%e0%b8%81%e0%b8%a3%e0%b8%a1-android-web-viewer/" data-count="vertical" data-via="" data-lang="de" data-text="เขียนโปรแกรม android : Web Viewer &raquo; Thai Coding #android #Web Viewer #หั [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p><strong>เขียนโปรแกรม android : Web Viewer</strong></p>
<p>หลังจากหายไปนานกลับบทความที่เกี่ยวการพัฒนาโปรแกรมใน android ผมก็กลับมาเขียนอีกครั้ง บ้างครั้งก็น้อยใจตัวเองที่ไม่มีปัญหาจะซื้อ smart phone ที่มีระบบปฏิบัติการ android กับเค้าซะทีจะได้ตั้งหน้าตั้งตาพัฒนา android application ?แล้วมันจำเป็นที่จะต้องมีมือถือ android ด้วยหรอ ? คำตอบก็คือคำว่าใช้ครับ เพราะลำพัง simulator ที่ติดมาใน eclipse นั้นไม่พอหรอกไหนจะลอง test โปรแกรมไหนจะ ทดสอบระบบ touch screen เพราะระบบ simulator นั้นไม่สามารถจะจำลองระบบสัมผัสได้นั้นเอง เอาเถอะไหนๆก็ไหนๆเขียนกันต่อไป บทความนี้จะเป็นเนื้อหาเกี่ยวกับ web viewer ซึ่งเป็นตัวที่ช่วยให้โปรแกรมเราเข้าเว็บได้ซึ่ง บ้างครั้งเราไม่ต้องการจะใช้ web browser ที่มากับมือถือก็สามารถใช้ web viewer ได้ซึ่งมันสามารถไปพัฒนาต่อเพื่อจะดึงค่าและกำหนดการแสดงผลของเว็บได้นะครับ</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/09/newproject1.jpg"><img class="alignnone size-full wp-image-1186" title="new project android" src="http://www.thaicoding.net/wp-content/uploads/2011/09/newproject1.jpg" alt="new project android" width="461" height="650" /></a></p>
<p><span id="more-1185"></span></p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/09/newproject11.jpg"><img class="alignnone size-full wp-image-1187" title="new project android" src="http://www.thaicoding.net/wp-content/uploads/2011/09/newproject11.jpg" alt="new project android" width="461" height="222" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>หลังจากได้สร้าง project แล้วสิ่งแรกที่ต้องทำการกำหนดคือหน้าตาของโปรแกรมซึ่งไปกำหนดในไฟล์ main.xml ซึ่งอยู่ใน res/layout/main.xml</p>
<p>ซึ่งกำหนด xml ดังนี้</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;horizontal&quot;
android:layout_width=&quot;fill_parent&quot;
android:layout_height=&quot;fill_parent&quot;
&gt;
&lt;LinearLayout
android:orientation=&quot;horizontal&quot;
android:layout_width=&quot;fill_parent&quot;
android:layout_height=&quot;wrap_content&quot;&gt;

&lt;EditText
android:id=&quot;@+id/url_field&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_weight=&quot;1.0&quot;
android:lines=&quot;1&quot;
android:inputType=&quot;textUri&quot;
android:imeOptions=&quot;actionGo&quot;/&gt;
&lt;Button
android:id=&quot;@+id/go_button&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;@string/go_button&quot; /&gt;
&lt;/LinearLayout&gt;
&lt;WebView
android:id=&quot;@+id/web_view&quot;
android:layout_width=&quot;fill_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_weight=&quot;1.0&quot; /&gt;
&lt;/LinearLayout&gt;
</pre>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/09/result1.jpg"><img class="alignnone size-full wp-image-1191" title="result" src="http://www.thaicoding.net/wp-content/uploads/2011/09/result1.jpg" alt="" width="557" height="396" /></a></p>
<p>รูปร่างตาหน้าจะได้ประมาณนี้ครับ แต่ก็จะได้แบบนี้ต้องไปกำหนด string ใน strings.xml ซึ่งอยู่ใน res/value/strings.xml ซึ่งในหน้าตาโปรแกรมเราได้มีการใช้ string ที่เปรียบเสมือนค่าคงที่อยู่คือ ตรง button ที่มีการกำหนดข้อความปุ่มให้เป็น android:text=<em>&#8220;@string/go_button&#8221;</em> ซึ่งไฟล์ strings.xml มีการกำหนดดังนี้</p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;resources&gt;
&lt;string name=&quot;hello&quot;&gt;Hello World, THCWebViewer!&lt;/string&gt;
&lt;string name=&quot;app_name&quot;&gt;THCWebViewer&lt;/string&gt;
&lt;string name=&quot;go_button&quot;&gt;Go&lt;/string&gt;
&lt;/resources&gt;
</pre>
<p>หลังจากที่เรากำหนดหน้าตาโปรแกรมเสร็จแล้วต่อไปก็คือโค้ดในส่วนของการทำงานซึ่งอยู่ในไฟล์? THCWebViewer.java หรือไฟล์ชื่ออื่นหากตั้งชื่อโปรเจ็คชื่ออื่นครับ แต่ถ้าชื่ออื่นอย่าลืมเปลี่ยนชื่อคลาสด้วยนะครับ</p>
<pre class="brush: java">
package org.thaicoding.webviewer;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.EditText;

public class THCWebViewer extends Activity {
/** Called when the activity is first created. */
private EditText urlText;
private Button goButton;

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

urlText = (EditText) findViewById(R.id.url_field);
goButton = (Button)findViewById(R.id.go_button);

goButton.setOnClickListener(new OnClickListener(){
public void onClick(View view)
{
openBrowser();
}
});

urlText.setOnKeyListener(new OnKeyListener()
{
public boolean onKey(View view, int keyCode, KeyEvent event){
if(keyCode == KeyEvent.KEYCODE_ENTER){
openBrowser();
return true;
}
return false;
}
});

}

private void openBrowser()
{
Uri uri = Uri.parse(urlText.getText().toString());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
}
</pre>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/09/result2.jpg"><img class="alignnone size-full wp-image-1190" title="result2" src="http://www.thaicoding.net/wp-content/uploads/2011/09/result2.jpg" alt="" width="574" height="408" /></a></p>
<p>เมื่อลองรันโปรแกรมแล้วเข้าเว็บดูก็จะได้ผลแบบในรูปครับแต่อย่าลืมเวลาเข้าเว็บให้พิมพ์ <a href="http://xn--%20-mml5d3a1v/">http:// ด้วย</a>นะครับเพราะตัวโปรแกรมยังไม่มีการตรวจสอบครับ ส่วนการทำงานของโปรแกรมนี้เริ่มแรกมาดูโครงสร้างตัวโปรแกรมก่อนประกอบด้วย</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/09/layout.jpg"><img class="alignnone size-full wp-image-1189" title="layout" src="http://www.thaicoding.net/wp-content/uploads/2011/09/layout.jpg" alt="layout" width="310" height="329" /></a></p>
<p>นี้เป็นการกำหนดหน้าตาในไฟล์ main.xml ครับซึ่งจะประกอบด้วย Edit Text, Button และ WebViewer การทำงานของโปรแกรมเริ่มจากประกาศตัวแปรสองตัวเพื่อเป็นควบคุม Edit Text กับ Button คือ</p>
<p>private EditText urlText;</p>
<p>private Button goButton;</p>
<p>ซึ่ง goButton มีการใส่การตรวจเหตุการณ์ในการคลิกที่ปุ่มคือ setOnClickListener ซึ่งเป็นการกำหนด action แบบ anonymous class ส่วน urlText ก็มีตรวจ events โดยใช้ setOnKeyListener? เมื่อมีการกดปุ่มซึ่งในโปรแกรมจะตรวจว่าเป็นปุ่ม enter หรือไม่ ซึ่งทั้งสองอันที่ตรวจจับเหตุการณ์นั้น เพื่อไปเรียกใช้งาน openBrowser(); ซึ่ง method นี้จะเป็นการร้องขอข้อมูลจาก url ที่ได้รับเข้ามา โดยใช้คลาส Uri? ของภาษาจาวานั้นเอง เมื่อได้รับข้อมูลแล้วก็ทำการแสดงผลผ่าน web viewer ซึ่งจะเห็นในบรรทัดที่มีคำสั่ง</p>
<p>Intent intent = new Intent(Intent.ACTION_VIEW, uri);</p>
<p>startActivity(intent);</p>
<p>บทความนี้ก็เป็นอันจบพบกันใหม่บทความหน้าครับ</p>
<p>&nbsp;</p>
<p><a href="http://www.mediafire.com/?0ynm76d3k1xoj06">Download Source</a></p>

	Tags: <a href="http://www.thaicoding.net/tag/android/" title="android" rel="tag">android</a>, <a href="http://www.thaicoding.net/tag/web-viewer/" title="Web Viewer" rel="tag">Web Viewer</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%ab%e0%b8%b1%e0%b8%94%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-android/" title="หัดเขียน android" rel="tag">หัดเขียน android</a>, <a href="http://www.thaicoding.net/tag/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%81%e0%b8%81%e0%b8%a3%e0%b8%a1-android/" title="เขียนโปรแกรม android" rel="tag">เขียนโปรแกรม android</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%81%e0%b8%81%e0%b8%a3%e0%b8%a1-android-web-viewer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เริ่มเขียน c++ กับ visual studio 2010</title>
		<link>http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-c-%e0%b8%81%e0%b8%b1%e0%b8%9a-visual-studio-2010/</link>
		<comments>http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-c-%e0%b8%81%e0%b8%b1%e0%b8%9a-visual-studio-2010/#comments</comments>
		<pubDate>Sun, 04 Sep 2011 12:04:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[ซีพลัส]]></category>
		<category><![CDATA[ภาษาซีพลัสพลัส]]></category>
		<category><![CDATA[หัดเขียนโปรแกรม]]></category>
		<category><![CDATA[เริ่มเขียน c++]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1173</guid>
		<description><![CDATA[Tweet ไม่ได้เขียนบทความนานร่วมเดือน ช่วงนี้ผมว่าจะหัดเขียน c++ ดูเลยทำให้ผมมาเขียนบทความนี้ c++ ถือว่าเป็นภาษาทางด้านการเขียนโปรแกรมที่ถือว่าทรงพลังอันหนึ่งเพราะมันได้รับประสิทธิภาพมาเต็มๆจากภาษาซี แต่ภาษาซีไม่มีแนวคิด oop แต่ในภาษา c++ นั้นมีซึ่งทำให้ c++ ถือเป็นภาษาหนึ่งที่สามารถพัฒนา application ได้มากมายและหลากหลาย และถ้าหากใครเขียน c++ ได้จนคล่องแล้วจะไปต่อยอดภาษาอื่นก็เป็นเรื่องง่ายไปเลย เอาละเรามาเริ่มเขียนภาษา c++ บน visual studio 2010 กันเลยดีกว่าโดยโปรแกรมจะเป็นโปรแกรมแปลงค่าเงินง่ายๆจากเงินดอลล่าร์สหรัฐ ไปเป็น เงินไทยโดยคูณ 30 เพราะเอาตัวเลขง่ายๆละกัน ผมคิดว่าเป็นโปรแกรมที่ไม่ยากเกินไม่ง่ายเกินไม่อยากเริ่มเขียนที่ Hello world มันเริ่มเบื่อละ อันละครั้งแรกก็เปิดโปรแกรม visual studio 2010 ขึ้นมาเลือกเป็น visual c++ จากนั้นก็สร้างโปรเจ็คเป็น window console application กด OK จากนั้นกด next แล้วเลือกเป็น empty project และก็ console application [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b9%2580%25e0%25b8%25a3%25e0%25b8%25b4%25e0%25b9%2588%25e0%25b8%25a1%25e0%25b9%2580%25e0%25b8%2582%25e0%25b8%25b5%25e0%25b8%25a2%25e0%25b8%2599-c-%25e0%25b8%2581%25e0%25b8%25b1%25e0%25b8%259a-visual-studio-2010%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-c-%e0%b8%81%e0%b8%b1%e0%b8%9a-visual-studio-2010/" data-count="vertical" data-via="" data-lang="de" data-text="เริ่มเขียน c++ กับ visual studio 2010 &raquo; Thai Coding #Visual Studio 2010 #ซ [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p>ไม่ได้เขียนบทความนานร่วมเดือน ช่วงนี้ผมว่าจะหัดเขียน c++ ดูเลยทำให้ผมมาเขียนบทความนี้ c++ ถือว่าเป็นภาษาทางด้านการเขียนโปรแกรมที่ถือว่าทรงพลังอันหนึ่งเพราะมันได้รับประสิทธิภาพมาเต็มๆจากภาษาซี แต่ภาษาซีไม่มีแนวคิด oop แต่ในภาษา c++ นั้นมีซึ่งทำให้ c++ ถือเป็นภาษาหนึ่งที่สามารถพัฒนา application ได้มากมายและหลากหลาย และถ้าหากใครเขียน c++ ได้จนคล่องแล้วจะไปต่อยอดภาษาอื่นก็เป็นเรื่องง่ายไปเลย</p>
<p>เอาละเรามาเริ่มเขียนภาษา c++ บน visual studio 2010 กันเลยดีกว่าโดยโปรแกรมจะเป็นโปรแกรมแปลงค่าเงินง่ายๆจากเงินดอลล่าร์สหรัฐ ไปเป็น เงินไทยโดยคูณ 30 เพราะเอาตัวเลขง่ายๆละกัน ผมคิดว่าเป็นโปรแกรมที่ไม่ยากเกินไม่ง่ายเกินไม่อยากเริ่มเขียนที่ Hello world มันเริ่มเบื่อละ อันละครั้งแรกก็เปิดโปรแกรม visual studio 2010 ขึ้นมาเลือกเป็น visual c++ จากนั้นก็สร้างโปรเจ็คเป็น window console application</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/09/newproject.jpg"><img class="alignnone size-full wp-image-1175" title="new project" src="http://www.thaicoding.net/wp-content/uploads/2011/09/newproject.jpg" alt="new project" width="565" height="391" /></a><span id="more-1173"></span></p>
<p>กด OK จากนั้นกด next แล้วเลือกเป็น empty project และก็ console application แบบในรูป</p>
<p>&nbsp;</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/09/setting.jpg"><img class="alignnone size-full wp-image-1176" title="setting" src="http://www.thaicoding.net/wp-content/uploads/2011/09/setting.jpg" alt="setting" width="545" height="464" /></a></p>
<p>&nbsp;</p>
<p>เมื่อสร้าง project เสร็จก็ให้ทำการคลิกขวาที่ folder Source Files แล้วเลือก Add &#8212; &gt; New Item</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/09/newfile.jpg"><img class="alignnone size-full wp-image-1177" title="newfile" src="http://www.thaicoding.net/wp-content/uploads/2011/09/newfile.jpg" alt="newfile" width="296" height="237" /></a></p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/09/newsourcecode.jpg"><img class="alignnone size-full wp-image-1178" title="new sourcecode" src="http://www.thaicoding.net/wp-content/uploads/2011/09/newsourcecode.jpg" alt="new sourcecode" width="557" height="386" /></a></p>
<p>แล้วเลือกสร้างไฟล์ .cpp ตั้งชื่อว่า main จากนั้นก็เขียนโค้ดดังนี้</p>
<pre class="brush: c++">

#include
#include

int main()
{
int usd = 0;
std::cout &lt;&lt; &quot;Please enter USD \n&quot;; 	std::cin &gt;&gt; usd;
std::cout &lt;&lt; &quot;Convert to thai bath: &quot; &lt;&lt; (usd * 30 ) &lt;&lt; &quot;\n&quot;;

system(&quot;PAUSE&quot;);
return 0;

}
</pre>
<p>จากผลลัพธ์จะเห็นว่าเมื่อใส่จำนวนเงินสหรัฐมันจะเอาไปคูณ 30 แล้วแสดงผล ในภาษา c++ นั้น จะมีการ #include &lt;cstdio&gt; มันก็คล้ายกับ stdio.h ในภาษาซีนั้นเอง ส่วน iostream นั้นก็ include เข้ามาเพื่อใช้คำสั่งเกี่ยวกับ input output ในส่วนของตัวโปรแกรมหลักนั้นก็ต้องมี function main แบบเดียวกับโปรแกรมในตระกูลภาษาซี จากนั้นมีการประกาศตัวแปร int ที่ชื่อว่า usd ส่วนคำสั่ง std::cout โดยใช้เครื่อง &lt;&lt; เป็นการบอกทิศทางข้อมูลว่าให้แสดงผลออกทางหน้าจอ ส่วนถ้าจะรับค่าจาก keyboard ให้ใช้ std::cin &gt;&gt; usd; เพื่อเอาค่าที่ได้ไปเก็บในตัวแปร usd นั้นเองส่วนการแปลงเงินนั้นก็เอาไปคูณ 30? จะเห็นว่ามีการใช้เครื่องหมาย &lt;&lt; ได้หลายๆครั้งเพื่อเป็นการส่งข้อมูลออกหน้าจอไปเป็นชุดนั้นเอง</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/09/result.jpg"><img class="alignnone size-full wp-image-1179" title="result" src="http://www.thaicoding.net/wp-content/uploads/2011/09/result.jpg" alt="" width="302" height="102" /></a></p>
<p>ก็หวังว่าโปรแกรมนี้จะเป็นจุดเริ่มต้นของการเรียนรู้ภาษา c++ ของคนที่เข้ามาอ่านในบล็อกแห่งนี้</p>

	Tags: <a href="http://www.thaicoding.net/tag/visual-studio-2010/" title="Visual Studio 2010" rel="tag">Visual Studio 2010</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%8b%e0%b8%b5%e0%b8%9e%e0%b8%a5%e0%b8%b1%e0%b8%aa/" title="ซีพลัส" rel="tag">ซีพลัส</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%a0%e0%b8%b2%e0%b8%a9%e0%b8%b2%e0%b8%8b%e0%b8%b5%e0%b8%9e%e0%b8%a5%e0%b8%b1%e0%b8%aa%e0%b8%9e%e0%b8%a5%e0%b8%b1%e0%b8%aa/" title="ภาษาซีพลัสพลัส" rel="tag">ภาษาซีพลัสพลัส</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%ab%e0%b8%b1%e0%b8%94%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%81%e0%b8%81%e0%b8%a3%e0%b8%a1/" title="หัดเขียนโปรแกรม" rel="tag">หัดเขียนโปรแกรม</a>, <a href="http://www.thaicoding.net/tag/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-c/" title="เริ่มเขียน c++" rel="tag">เริ่มเขียน c++</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-c-%e0%b8%81%e0%b8%b1%e0%b8%9a-visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

