ผู้ติดตาม

วันจันทร์ที่ 2 เมษายน พ.ศ. 2555

วัน อังคาร  ที่ 20  มีนาคม  2555


      ทำ Application ที่ 2 เป็น ชื่อ WebBrowser เพื่อทดสอบความเข้าใจเกี่ยวกับ Android

-----------------------------------------------------------------------------------------------------------
ไฟล์ Activity.java
package com.fibo.webbrowser;         // ที่อยู๋ package

import android.app.Activity;             // import ไฟล์ต่างๆ
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class WebBrowserActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    public void Go (View v){
   
        //  สร้างตัวแปลแบบ Edittext เพื่อรับค่าจากหน้า Main.xml
    EditText Web = (EditText) findViewById(R.id.editText1) ;      
   
        // สร้าง intent เพื่อใช้ส่งค่าตัวแปล ผ่าน Uri.parse
        // คำสั่ง Web.getText().toString()) รับค่าข้อความจาก edittext
    Intent AA = new Intent (android.content.Intent.ACTION_VIEW,Uri.parse("http://"+Web.getText().toString()));
        
       // แสดงข้อความ
    Toast.makeText(this,"Go to:"+Web.getText().toString(),Toast.LENGTH_SHORT).show();
    startActivity(AA);
    }

      // ฟังก์ชันทีเรียกใช้ เมื่อกดปุ่ม shortcut ไปยังหน้าเว็บต่างๆ
    public void GoFB (View v){
    Intent AA = new Intent (android.content.Intent.ACTION_VIEW,Uri.parse("http://www.facebook.com"));
        Toast.makeText(this,"Go to:www.facebook.com",Toast.LENGTH_SHORT).show();
    startActivity(AA);
    }
    public void GoGoogle (View v){
    Intent AA = new Intent (android.content.Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
        Toast.makeText(this,"Go to:www.google.com",Toast.LENGTH_SHORT).show();
    startActivity(AA);
    }
    public void GoYoutube (View v){
    Intent AA = new Intent (android.content.Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com"));
        Toast.makeText(this,"Go to:www.youtube.com",Toast.LENGTH_SHORT).show();
    startActivity(AA);
    }
    public void GoTwitter (View v){
    Intent AA = new Intent (android.content.Intent.ACTION_VIEW,Uri.parse("http://www.twitter.com"));
        Toast.makeText(this,"Go to:www.twitter.com",Toast.LENGTH_SHORT).show();
    startActivity(AA);
    }
}


ไม่มีความคิดเห็น:

แสดงความคิดเห็น