Android Tab Menu แบบง่ายๆ

การทำ Tab Menu จะมีด้วยกัน 2 ไฟล์ คือ activity_main.xml และ MainActivity.java



กรณีนี้จะใช้เพียง activity_main เดียวในการสลับหน้าไปมา

Example : activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </TabWidget>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="One" />
                
            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab2"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
                <TextView
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Two" />
                    
            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab3"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
                <TextView
                    android:id="@+id/textView5"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Three" />
            
            </LinearLayout>
            
        </FrameLayout>
    </LinearLayout>
</TabHost>

Example : MainActivity.java
package com.example.tabhost1;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TabHost;

public class MainActivity extends Activity {

 TabHost mTabHost;
 
   
 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        mTabHost = (TabHost) findViewById(android.R.id.tabhost);
        mTabHost.setup();
        
        mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("One").setContent(R.id.tab1));
        mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Two").setContent(R.id.tab2));
        mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("Three").setContent(R.id.tab3));
        
        mTabHost.setCurrentTab(0);
      
    }
 
}

ผลลัพธ์ : 





























ที่มา : Thaicreate

Android Dialog Toast

การทำ Dialog Toast จะมีด้วยกัน 2 ไฟล์ คือ activity_main.xml และ MainActivity.java




Example : activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="18dp"
        android:text="Input Text ?" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:text="Show Toast" />

</RelativeLayout>

Example : MainActivity.java
package com.example.alertdialog2;

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


public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
               
        final Button btn1 = (Button) findViewById(R.id.button1);

        final TextView editT1 = (TextView)findViewById(R.id.editText1);

        btn1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                String strTxt = editT1.getText().toString();               
        Toast.makeText(MainActivity.this,
            "ข้อความของคุณคือ : " + strTxt,
            Toast.LENGTH_LONG).show();                
            }
        });
        
    }
}

ผลลัพธ์ : 



























ที่มา : Thaicreate

Android Dialog Popup

การทำ Dialog Popup จะมีด้วยกัน 2 ไฟล์ คือ activity_main.xml และ MainActivity.java




Example : activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="18dp"
        android:text="Input Text ?" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:text="Show AlertDialog" />

</RelativeLayout>
Example : MainActivity.java
package com.example.alertdialog1;

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


public class MainActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        final AlertDialog.Builder adb = new AlertDialog.Builder(this);

        final Button btn1 = (Button) findViewById(R.id.button1);
        
        final TextView editT1 = (TextView)findViewById(R.id.editText1);

        btn1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                AlertDialog ad = adb.create();
                String strTxt = editT1.getText().toString();

                ad.setMessage("ข้อความของคุณคือ : " + strTxt);
                ad.show();
            }
        });
        
    }

}

ผลลัพธ์ : 



























ที่มา : Thaicreate

Android RatingBar in AlertDialog Popup

นการสร้าง RatingBar บน Dialog Popup สามารถสร้างโดยใช้วิธีการ Set View บน Dialog โดยเรียก Widgets RatingBar ที่ได้จากการสร้างขึ้นมาใหม่บน Dynamic Runtime ประกอบไปด้วย 2 ไฟล์ คือ MainActivity.java กับ activity_main.xml



Example : activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="35dp"
        android:text="Click" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="51dp"
        android:text="result" />

</RelativeLayout>
Example : MainActivity.java
package com.rating.rating2;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.TextView;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;

public class MainActivity extends Activity {

 public TextView txtView;
 
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
        
    if (android.os.Build.VERSION.SDK_INT > 9) {
             StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
             StrictMode.setThreadPolicy(policy);
         }
  
  txtView = (TextView)findViewById(R.id.textView1); // TextView
  
        // Button1
        final Button btn1 = (Button) findViewById(R.id.button1);
        btn1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
             final AlertDialog.Builder popDialog = new AlertDialog.Builder(MainActivity.this);
          final RatingBar rating = new RatingBar(MainActivity.this);
          rating.setMax(5);

          popDialog.setIcon(android.R.drawable.btn_star_big_on);
          popDialog.setTitle("Vote!! ");
          popDialog.setView(rating);

          // Button OK
          popDialog.setPositiveButton(android.R.string.ok,
            new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int which) {
              txtView.setText(String.valueOf(rating.getProgress()));
              dialog.dismiss();
             }

            })

          // Button Cancel
            .setNegativeButton("Cancel",
              new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
               }
              });

          popDialog.create();
          popDialog.show();
            } 
        });
        
 }
}


 สามารถ set เพิ่มหรือลดจำนวนดาวได้ที่โค้ด rating.setMax();

ผลลัพธ์ :

ที่มา : Thaicreate

Android RatingBar in Layout

การเรียกใช้ Rating Bar บน Layout ธรรมดา จะประกอบไปด้วย 2 ไฟล์คือ MainActivity.java กับ activity_main.xml และแก้ไขไฟล์ string.xml




Example : string.xml
<resources>
    <string name="app_name">Rating1</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="text_label_1">Rate</string>
    <string name="button_label">Submit</string>
    <string name="text_label_2">Result: </string>
</resources>
Example : activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/lblRateMe"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/text_label_1"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="4"
        android:stepSize="1.0"
        android:rating="2.0" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_label" />

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/lblResult"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/text_label_2"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/txtRatingValue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textAppearance="?android:attr/textAppearanceSmall" />

    </LinearLayout>

</LinearLayout>
เราสามารถเพิ่มหรือลดจำนวนดาวได้จากโค้ด android:numSters="" 

Example : MainActivity.java
package com.rating.rating1;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

   private RatingBar ratingBar;
   private TextView ratingValue;
   private Button button;

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

  addListenerOnRatingBar();
  addListenerOnButton();

   }

   public void addListenerOnRatingBar() {

  ratingBar = (RatingBar) findViewById(R.id.ratingBar);
  ratingValue = (TextView) findViewById(R.id.txtRatingValue);

  ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

   public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {

    ratingValue.setText(String.valueOf(rating));

   }
  });
   }

   public void addListenerOnButton() {

  ratingBar = (RatingBar) findViewById(R.id.ratingBar);
  button = (Button) findViewById(R.id.button);

  button.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {

    Toast.makeText(MainActivity.this, String.valueOf(ratingBar.getRating()), Toast.LENGTH_LONG).show();
   }

  });

   }
 }

ผลลัพธ์ :




























ที่มา : javacodegeeks

Android การทำแผนที่บนมือถือ

การทำ Google Map บน Android สามารถทำได้ดังนี้

เตรียมคาวมพร้อมก่อนทำ Map (สำหรับผู้ใช้งานโปรแกรม eclipse)

ให้ดาว์โหลด ติดตั้ง ไฟล์ที่อยู่ใน SDK ดังต่อไปนี้ให้

- Google Play services




วิธีการหาไฟล์ Google play services




Exmaple : AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google.googlemap1"
    android:versionCode="1"
    android:versionName="1.0" >
    
 <uses-permission android:name="android.permission.INTERNET"/>
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 <!-- The following two permissions are not required to use
      Google Maps Android API v2, but are recommended. -->
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="21" />
    
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        
        <activity
            android:name="com.google.googlemap1.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <meta-data
      android:name="com.google.android.maps.v2.API_KEY"
      android:value="API_KEY"/>
        
        <meta-data
      android:name="com.google.android.gms.version"
      android:value="@integer/google_play_services_version" />
        
    </application>

</manifest>
ปล. API_KEY เราต้องทำการสร้าง Key ใหม่ขึ้นมาก่อนสามารถทำได้ดัง วิดีโอต่อไปนี้






Link ไปยัง Google APIs Console คลิก

วิธีการ import ไฟล์ google-play-services_lib





Exmaple : activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"/>
Exmaple : MainActivity.java
package com.google.googlemap1;

import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}
ผลลัพธ์ที่ได้
























ขอขอบคุณที่มา : Google Developers

Program ที่ใช้สร้างเว็บเพจ

Program ที่ช่วยในการสร้างเว็บเพจมีอยู่หลายโปรแกรมในปัจจุบัน ขึ้นอยู่กับรูปแบบของเว็บเพจ
ส่วนใหญ่การเขียนโปรแกรม HTML เพื่อสร้างเว็บเพจนั้น เราสามารถใช้โปรแกรม Text Editor ทั่วๆ ไปได้เลย เช่น Notepad ที่ติดตั้งมาพร้อมกับ window อยู่แล้วก็ได้

แนะนำโปรแกรม sublime text เป็นโปรแกรมไว้สำหรับเขียนโปรแกรมได้หลายภาษา เช่น C, C#, C++, Java, HTML, PHP เป็นต้น  และทำการแบ่งชั้น สี ตำแหน่งของข้อความที่เราพิมพ์เป็นชั้นๆ ทำให้ง่ายต่อการดูหรือแก้ไข ซึ่งสามารถดาว์โหลดได้จาก ลิ้งข้างล่างนี้

Download sublime text : www.sublimetext.com/