나머지 세팅값은 intent의 예제를 참고 하세요~
<?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:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="나는 main" />

    <RatingBar
        android:id="@+id/ratingBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/button2"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="전화하기" />

    <Button
        android:id="@+id/button3"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="문자보내기" />

    <Button
        android:id="@+id/button4"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="인터넷" />

    <Button
        android:id="@+id/button5"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="동영상보기" />

</LinearLayout>
package com.gusfree.intent;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class IntentActivity extends Activity implements 
OnClickListener{

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		findViewById(R.id.button1).setOnClickListener(this);
		findViewById(R.id.button2).setOnClickListener(this);
		findViewById(R.id.button3).setOnClickListener(this);
		findViewById(R.id.button4).setOnClickListener(this);
		findViewById(R.id.button5).setOnClickListener(this);

		//Context 메뉴를 어떤 뷰에 셋팅할 것인가.
		registerForContextMenu(findViewById(R.id.button4));
		
		Log.i("onCreate", "onCreate 시작");
	}

	@Override
	public void onClick(View v) {
		Log.w("onClick","버튼 눌렀다");
		int id=v.getId();
		Log.i("아이디","아이디"+id);
		switch(v.getId()){

		case R.id.button1 :

			//버튼 누르면 Sub로 Activity간 이동하기
			Intent intent=new Intent();

			intent.setClass(this, SubActivity.class);

			//intent에 데이터 binding하기		
			intent.putExtra("name", "park!");

			//startActivity(intent); //이동

			//Activity이동하고 되돌아오면 onActivityResult호출
			startActivityForResult(intent, 1000); //requestCode

			break;

		case R.id.button2://전화하기
			Intent intent2 =new Intent();
			intent2.setAction(Intent.ACTION_CALL);
			Uri uri = Uri.parse("tel:0101234578");
			intent2.setData(uri);//Uri
			startActivity(intent2);//error permission Call_Phone

			//Uri : Uniform Resource Identifier
			//naver.com  => http://www.naver.com/
			//"0101234578"  => "tel:0101234578"
			break;
     
		case R.id.button3:
			Intent intent3 =new Intent();
			intent3.setAction(Intent.ACTION_SENDTO);
			Uri uri2 = Uri.parse("sms:0101234578");
			intent3.setData(uri2);//Uri
			startActivity(intent3);
			break;

		case R.id.button4://인터넷 하기
			Intent intent4=new Intent();
			/* class Intent{
			 * 		static String ACTION_VIEW="android.intent.action.VIEW"
			 * }
			 * */			
			intent4.setAction("android.intent.action.VIEW");
			intent4.setData(Uri.parse("http://gusfree.tistory.com"));
			startActivity(intent4);
			break;
			
		case R.id.button5://동영상 보기
			Intent intent5=new Intent();
			intent5.setAction("android.intent.action.VIEW");
			intent5.setData(Uri.parse("http://youtu.be/DhWCojA0BHA"));
			startActivity(intent5);
			break;
		}
	}

	@Override //3번째 파라미터가 인텐트!
	//1param =1000, 2param = 777, 3param=theIntent
	protected void onActivityResult(int requestCode, 
			int resultCode, Intent data) {

		if(requestCode==1000){//requestCode사용 예

			if(resultCode==777){//resultcode사용예
				String id=data.getStringExtra("id");
				int month=data.getIntExtra("month", 12);

				Toast.makeText(this, id+month, 0).show();
			}else{
			}
			//super.onActivityResult(requestCode, resultCode, data);
		}
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add("메뉴1").setIcon(R.drawable.red);
		MenuItem item1 =menu.add("메뉴2");
		item1.setIcon(R.drawable.yellow);		
		//menu.add("메뉴2").setIcon(R.drawable.yellow);
		
		//그룹아이디, 메뉴 아이템이 아이디, 보여지는 순서 타이틀
		menu.add(100,    10         ,1,"빨간색");
		//           menuItem id
		menu.add(100,11,2,"노란색");
		return super.onCreateOptionsMenu(menu);
	}
	//콜백 메서드(callBack): on~ 시스템이 호출한다.
	//OptionsItemSelected 상황이 발생할 때 호출
	@Override//옵션 아이템을 클릭/선택 하면 호출되는 메신저
	public boolean onOptionsItemSelected(MenuItem item) {
		int id=item.getItemId();
		switch(id){
		case 10:
			findViewById(R.id.button1).setBackgroundColor(Color.RED);
		break;
		case 11:
			findViewById(R.id.button1).setBackgroundColor(Color.YELLOW);
		break;
		}
		return super.onOptionsItemSelected(item);
	}
	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		menu.add(200,20,1,"흰색");
		menu.add(200,21,3,"금색");
		super.onCreateContextMenu(menu, v, menuInfo);
	}
	@Override
	public boolean onContextItemSelected(MenuItem item) {
		switch(item.getItemId()){
		case 20:
			findViewById(R.id.button4).setBackgroundColor(Color.WHITE);
			break;
		case 21:
			findViewById(R.id.button4).setBackgroundColor(Color.rgb(200, 75, 33));
			break;
		}
		return super.onContextItemSelected(item);
	}
}	





'Android > 2012.04월 강좌' 카테고리의 다른 글

6일차 Menu 2 (Option menu)  (0) 2012.05.03
6일차 복습  (0) 2012.05.03
5일차 Menu (Option Menu, Context Menu)  (0) 2012.05.02
5일차 Intent 3 전화걸기 문자보내기 인터넷  (2) 2012.05.02
5일차 Intent2  (2) 2012.05.02

+ Recent posts