<?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" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:src="@drawable/ic_launcher" />

    <ToggleButton
        android:id="@+id/toggleButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ToggleButton" 
        android:layout_gravity="right"/>

    <ToggleButton
        android:id="@+id/toggleButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ToggleButton" 
        android:layout_gravity="right"/>

</LinearLayout>

package com.gusfree.frameAnimation;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.ToggleButton;

public class FrameAnimationActivity extends Activity {
	ImageView imageView;
	ToggleButton toggle;
	AnimationDrawable ani;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		imageView=(ImageView)findViewById(R.id.imageView1);
		toggle =(ToggleButton)this.findViewById(R.id.toggleButton1);
		//프레임 에니메이션 객체를 만들자.
		ani = new AnimationDrawable();
		
		Resources res = getResources();//리소스 가져와라
		ani.addFrame(res.getDrawable(R.drawable.red),300);//1000이 1초 ,500=0.5초
		ani.addFrame(res.getDrawable(R.drawable.blue),300);
		ani.addFrame(res.getDrawable(R.drawable.yellow),300);
		
		//에니메이션 무한반복 셋팅하자.
		ani.setOneShot(false);
		
		//에니메이션 객체를 이미지뷰에 셋팅하자
		imageView.setImageDrawable(ani);
		
		toggle.setOnCheckedChangeListener(new OnCheckedChangeListener(){

			@Override
			//메서드 체크바꼈을 때
			public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
				if(isChecked){
					ani.start();
				}else{
					ani.stop();
				}
			}
		});
	}
}



012


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

6일차 TwinAnimaion  (0) 2012.05.03
6일차 FrameAnimation 2(xml로 만드 애니메이션 이미지뷰 셋팅)  (0) 2012.05.03
6일차 Dialog  (0) 2012.05.03
6일차 Menu 2 (Option menu)  (0) 2012.05.03
6일차 복습  (0) 2012.05.03
<?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="Dialog" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="AlertDialog" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="DatePickerDialog" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TimePickerDialog" />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ProgressDialog" />

</LinearLayout>
package com.gusfree.dialog;


import java.util.Calendar;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;
import android.widget.Toast;

public class DialogActivity extends Activity {
	Activity act;
	DialogListener dListener = new DialogListener();

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

		act=this;
		Listener list = new Listener();

		findViewById(R.id.button1).setOnClickListener(list);
		findViewById(R.id.button2).setOnClickListener(list);
		findViewById(R.id.button3).setOnClickListener(list);
		findViewById(R.id.button4).setOnClickListener(list);
		findViewById(R.id.button5).setOnClickListener(list);
	}
	//inner class
	class Listener implements OnClickListener{


		@Override
		public void onClick(View v) {

			Button btn =(Button) v;
			dListener = new DialogListener();

			switch(v.getId()){
			case R.id.button1://222456777와 같은 주소번호
				btn.setText("다이얼로그 기본");
				//new Dialog(DialogActivity.this);
				Dialog dialog1=new Dialog(act);
				dialog1.setTitle("다이얼로그");
				dialog1.setContentView(R.layout.main);
				dialog1.show();
				break;

			case R.id.button2:
				AlertDialog.Builder builder = new AlertDialog.Builder(act);
				builder.setIcon(R.drawable.red);
				builder.setTitle("Red Bird");
				builder.setMessage("별명을 알고 싶나?");
				/*//android.view.View.OnClickListener;
				//android.content.DialogInterface.OnClickListener
				builder.setPositiveButton("OK",new android.content.
						DialogInterface.OnClickListener(){

					@Override
					public void onClick(DialogInterface dialog, int which) {
						switch(which){
						//case -1:
						case DialogInterface.BUTTON_POSITIVE:
						//기능구현
						Toast.makeText(act, "Syrup Finch", 0).show();
						}
					}});*/
				builder.setPositiveButton("Postive id:-1", dListener);
				builder.setNeutralButton("Neutral id:-2", dListener);
				builder.setNegativeButton("Negative id:-3", dListener);
				builder.show();
				break;

			case R.id.button3:
				Calendar cal = Calendar.getInstance();
				DatePickerDialog dpd = 
						new DatePickerDialog(act, 
								new DatePickerDialog.OnDateSetListener() {

							@Override
							public void onDateSet(DatePicker view, 
									int year, 
									int monthOfYear,
									int dayOfMonth) {
								Toast.makeText(act,
										year+"."+(monthOfYear+1)+"."+dayOfMonth,
										Toast.LENGTH_SHORT).show();
							}
						}, 
						cal.get(Calendar.YEAR),
						cal.get(Calendar.MONTH), 
						cal.get(Calendar.DAY_OF_MONTH));
				dpd.show();
				break;

			case R.id.button4:
				Calendar cal2 = Calendar.getInstance();
				new TimePickerDialog(act, 
						new TimePickerDialog.OnTimeSetListener() {

					@Override
					public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
						Toast.makeText(act, hourOfDay+":"+minute, 
								Toast.LENGTH_SHORT).show();
					}
				},
				cal2.get(Calendar.HOUR_OF_DAY),
				cal2.get(Calendar.MINUTE), 
				false).show();

				break;

			case R.id.button5:
				ProgressDialog pDialog=new ProgressDialog(act);
				pDialog.setTitle("ProgressDialog");
				pDialog.setMessage("실행되라~~");
				pDialog.setIcon(R.drawable.blue);
				pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
				pDialog.show();
				pDialog.setProgress(50);
				break;
			}
		}
	}
	class DialogListener implements android.content.DialogInterface.OnClickListener{

		@Override
		public void onClick(DialogInterface dialog, int button) {
			switch(button){
			case -1://case DialogInterface.BUTTON_POSITIVE:
				Toast.makeText(act, "Syrup Finch", 0).show();
				break;
			case -2:
				Toast.makeText(act, "테스트", 0).show();
				break;
			case -3:
				Toast.makeText(act, "테스트", 0).show();
				break;
			}
		}
	}
}package com.gusfree.dialog;


import java.util.Calendar;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;
import android.widget.Toast;

public class DialogActivity extends Activity {
	Activity act;
	DialogListener dListener = new DialogListener();

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

		act=this;
		Listener list = new Listener();

		findViewById(R.id.button1).setOnClickListener(list);
		findViewById(R.id.button2).setOnClickListener(list);
		findViewById(R.id.button3).setOnClickListener(list);
		findViewById(R.id.button4).setOnClickListener(list);
		findViewById(R.id.button5).setOnClickListener(list);
	}
	//inner class
	class Listener implements OnClickListener{


		@Override
		public void onClick(View v) {

			Button btn =(Button) v;
			dListener = new DialogListener();

			switch(v.getId()){
			case R.id.button1://222456777와 같은 주소번호
				btn.setText("다이얼로그 기본");
				//new Dialog(DialogActivity.this);
				Dialog dialog1=new Dialog(act);
				dialog1.setTitle("다이얼로그");
				dialog1.setContentView(R.layout.main);
				dialog1.show();
				break;

			case R.id.button2:
				AlertDialog.Builder builder = new AlertDialog.Builder(act);
				builder.setIcon(R.drawable.red);
				builder.setTitle("Red Bird");
				builder.setMessage("별명을 알고 싶나?");
				/*//android.view.View.OnClickListener;
				//android.content.DialogInterface.OnClickListener
				builder.setPositiveButton("OK",new android.content.
						DialogInterface.OnClickListener(){

					@Override
					public void onClick(DialogInterface dialog, int which) {
						switch(which){
						//case -1:
						case DialogInterface.BUTTON_POSITIVE:
						//기능구현
						Toast.makeText(act, "Syrup Finch", 0).show();
						}
					}});*/
				builder.setPositiveButton("Postive id:-1", dListener);
				builder.setNeutralButton("Neutral id:-2", dListener);
				builder.setNegativeButton("Negative id:-3", dListener);
				builder.show();
				break;

			case R.id.button3:
				Calendar cal = Calendar.getInstance();
				DatePickerDialog dpd = 
						new DatePickerDialog(act, 
								new DatePickerDialog.OnDateSetListener() {

							@Override
							public void onDateSet(DatePicker view, 
									int year, 
									int monthOfYear,
									int dayOfMonth) {
								Toast.makeText(act,
										year+"."+(monthOfYear+1)+"."+dayOfMonth,
										Toast.LENGTH_SHORT).show();
							}
						}, 
						cal.get(Calendar.YEAR),
						cal.get(Calendar.MONTH), 
						cal.get(Calendar.DAY_OF_MONTH));
				dpd.show();
				break;

			case R.id.button4:
				Calendar cal2 = Calendar.getInstance();
				new TimePickerDialog(act, 
						new TimePickerDialog.OnTimeSetListener() {

					@Override
					public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
						Toast.makeText(act, hourOfDay+":"+minute, 
								Toast.LENGTH_SHORT).show();
					}
				},
				cal2.get(Calendar.HOUR_OF_DAY),
				cal2.get(Calendar.MINUTE), 
				false).show();

				break;

			case R.id.button5:
				ProgressDialog pDialog=new ProgressDialog(act);
				pDialog.setTitle("ProgressDialog");
				pDialog.setMessage("실행되라~~");
				pDialog.setIcon(R.drawable.blue);
				pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
				pDialog.show();
				pDialog.setProgress(50);
				break;
			}
		}
	}
	class DialogListener implements android.content.DialogInterface.OnClickListener{

		@Override
		public void onClick(DialogInterface dialog, int button) {
			switch(button){
			case -1://case DialogInterface.BUTTON_POSITIVE:
				Toast.makeText(act, "Syrup Finch", 0).show();
				break;
			case -2:
				Toast.makeText(act, "테스트", 0).show();
				break;
			case -3:
				Toast.makeText(act, "테스트", 0).show();
				break;
			}
		}
	}
}

















menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu 
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <group android:id="@+id/group1">
        <item android:id="@+id/item1" android:title="해태"></item>
        <item android:id="@+id/item2" android:title="쌍방울"></item>
        <item android:id="@+id/item3" android:title="삼미"></item>
        <item android:id="@+id/item4" android:title="다른팀">
            <menu>
                <item android:id="@+id/item5" android:title="빙그레"/>
                <item android:id="@+id/item6" android:title="기아"/>
            </menu>
        </item>
    </group>   
</menu>
MenuActivity.java
package com.gusfree.menu;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

public class MenuActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}

	//최초로 menu버튼 누를때 호출됩니다. 
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// 뷰를 불러올때 View.inflate(this, R.layout.main, null);

		//menu폴더안에 있는 menu.xml을 불러와서 사용하자
		MenuInflater menuInflate=new MenuInflater(this); 
		menuInflate.inflate(R.menu.menu, menu);    	
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		Toast.makeText(this,
				item.getTitle()+", id:"+item.getItemId(),0).show();

		switch(item.getItemId()){
		case R.id.item1:
			
			break;
		case R.id.item2:

			break;
		}
		return super.onOptionsItemSelected(item);
	}
}  








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

6일차 FrameAnimation  (2) 2012.05.03
6일차 Dialog  (0) 2012.05.03
6일차 복습  (0) 2012.05.03
5일차 intent 4 (추가- Uri 동영상보기)  (0) 2012.05.02
5일차 Menu (Option Menu, Context Menu)  (0) 2012.05.02
모델1 방식 프로그래밍

게시판  
  글쓴사람/글제목/글내용/작성일/비번/조회수/답글수
  resultSet(10개의 글이 들어있다)
  Item 객체 10개를 만든다.
  ArrayList.add(Item) *10 번 
  ListView 에 arrayList 를 출력 
  
class Item{
   private String 글쓴사람;
   String 글제목;
   ...
   int 조회수;
   int 답글수;

   
}






GridView  : AdapteView 종류 

<GridView>
  <이미지뷰>  0
  <이미지뷰>  1
  <레이아웃>  2
      <이미지뷰/>
      <텍스트뷰/>
      <버튼/>
  </레이아웃>
</GridView>

BaseAdapter
   getCount() return (3)데이터가 총 몇개냐; 
   getView(int 포지션,   ,  ){
      // 1. 이미지뷰를 new ImageView() 만들어서
      //    그 안에 이미지를 셋팅하기
   
      // 2. xml로 만든 image.xml 불러와서 inflate
      //    그 안에 이미지를 셋팅하기  
      return <이미지뷰>;
   }

EditText 2개 라디오그룹 1개 TextView 1개
EditText에서는 입력된 값을 가져오기
Integer.parseInt(
   에디트텍스트객체.getText().toString());

<라디오그룹>
  <라디오버튼/>
  <라디오버튼/>
  <라디오버튼/>
</라디오그룹>

리디오그룹객체.setOnCheckedChangeListener()
  switch(어떤것이 체크가 되었나) {
    case 첫번째 라디오버튼 :
       텍스트뷰.setText(x + y );
  }
계산기 
findView * 4 번 : editText2개 텍스트뷰 라디오그룹
라디오그룹에 리스너를 셋팅(체크가 변했을때 부르는)

에디트텍스트객체.getText().toString();//문자가져옴
int x = Integer.parse(숫자로 바꿀 문자);//형변환


나머지 세팅값은 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



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);

		//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;
		}
	}

	@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);
	}
}	




메뉴를 클릭 선택한거에 따라서 button1 색이 바뀐다.(Option Menu라고 한다.)



button4를 길게 누르면 menu가 나오고 선택한거에 따라 버튼 색이 바뀐다.(Context Menu)





<?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="인터넷" />

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

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



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gusfree.intent"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.CALL_PHONE"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".IntentActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="SubActivity"></activity>
    </application>

</manifest>
package com.gusfree.intent;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
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);

		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;
		}
	}

	@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);
		}
	}
}	
package com.gusfree.intent;

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

public class SubActivity extends Activity implements OnClickListener{
	Intent theInent;//객체 선언
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sub);
		
		Button btn = (Button)findViewById(R.id.button1);
		btn.setOnClickListener(this);
		
		//intent에 binding된 데이터 읽기
		theInent = getIntent();//(객체 초기화)나를 호출한 인텐트 찾기
		String name=theInent.getStringExtra("name");//키
		btn.setText(name+btn.getText());
	}

	@Override
	public void onClick(View arg0) {
		
		theInent.putExtra("id", "com.gusfree.intent");
		theInent.putExtra("month", 5);
		
		//forResult로 왔을때 사용해야 되는 메서드
		setResult(777, theInent);//resultCode
		
		finish();//액티비티 종료
	}
}






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

5일차 intent 4 (추가- Uri 동영상보기)  (0) 2012.05.02
5일차 Menu (Option Menu, Context Menu)  (0) 2012.05.02
5일차 Intent2  (2) 2012.05.02
5일차 LogCat을 사용한 error 찾기  (0) 2012.05.02
5일차 Intent  (0) 2012.05.02


IntentActivity.java
package com.gusfree.intent;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
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);

		Log.i("onCreate", "onCreate 시작");
	}

	@Override
	public void onClick(View v) {

		// 에러찾을때 
		Log.w("onClick","버튼 눌렀다");
		//버튼 누르면 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

	}

	@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);
		}
	}
}	
SubActivity.java
package com.gusfree.intent;

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

public class SubActivity extends Activity implements OnClickListener{
	Intent theIntent;//객체 선언
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sub);
		
		Button btn = (Button)findViewById(R.id.button1);
		btn.setOnClickListener(this);
		
		//intent에 binding된 데이터 읽기
		theIntent = getIntent();//(객체 초기화)나를 호출한 인텐트 찾기
		String name=theIntent.getStringExtra("name");//키
		btn.setText(name+btn.getText());
	}

	@Override
	public void onClick(View arg0) {
		
		theIntent.putExtra("id", "com.gusfree.intent");
		theIntent.putExtra("month", 5);
		
		//forResult로 왔을때 사용해야 되는 메서드
		setResult(777, theIntent);//resultCode
		
		finish();//액티비티 종료
	}
}




다시 눌렀을때~~


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

5일차 Menu (Option Menu, Context Menu)  (0) 2012.05.02
5일차 Intent 3 전화걸기 문자보내기 인터넷  (2) 2012.05.02
5일차 LogCat을 사용한 error 찾기  (0) 2012.05.02
5일차 Intent  (0) 2012.05.02
5일차 Grid  (0) 2012.05.02
package com.gusfree.intent;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;

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);
        
        Log.i("onCreate","onCreate 시작");
    }

	@Override
	public void onClick(View v) {
		
		//에러찾을 때 
		Log.w("onClick","버튼을 눌렀다.");
		//버튼 누르면 Sub로 Activity간 이동하기
		Intent intent =new Intent();
		Log.w("onClick","1");
		intent.setClass(this, SubActivity.class);
		Log.w("onClick","2");
		startActivity(intent);//이동//error
		Log.w("onClick","3");
	}
}






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

5일차 Intent 3 전화걸기 문자보내기 인터넷  (2) 2012.05.02
5일차 Intent2  (2) 2012.05.02
5일차 Intent  (0) 2012.05.02
5일차 Grid  (0) 2012.05.02
5일차 계산기  (0) 2012.05.02
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: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" />

</LinearLayout>
sub.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

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

</LinearLayout>
IntentActivity.java 23번 줄 에러 로 manifest설정 




androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gusfree.intent"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".IntentActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="SubActivity"></activity>
    </application>

</manifest>
IntentActivity.java
package com.gusfree.intent;

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

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);
    }

	@Override
	public void onClick(View v) {
		//버튼 누르면 Sub로 Activity간 이동하기
		Intent intent =new Intent();
		intent.setClass(this, SubActivity.class);
		startActivity(intent);//이동//error
	}
}
SubActivity.java
package com.gusfree.intent;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class SubActivity extends Activity implements OnClickListener{
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sub);
		
		findViewById(R.id.button1).setOnClickListener(this);
	}

	@Override
	public void onClick(View arg0) {
		finish();//액티비티 종료
	}
}






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

5일차 Intent2  (2) 2012.05.02
5일차 LogCat을 사용한 error 찾기  (0) 2012.05.02
5일차 Grid  (0) 2012.05.02
5일차 계산기  (0) 2012.05.02
5일차 계산기(내가 한것)  (0) 2012.05.02
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" 
    android:id="@+id/layout">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <GridView
        android:id="@+id/gridView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:numColumns="3" >
        <!-- android:numColumns="auto_fit"-->
        
    </GridView>

</LinearLayout>
item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="100px"
        android:layout_height="100px"
        android:src="@drawable/ic_launcher" />

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

</LinearLayout>
GridViewActivity.java
package com.gusfree.gridview;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class GridViewActivity extends Activity {
    GridView gridView;
    ArrayList<Data> list=new ArrayList<Data>();  //collection
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main); //inflate        
        gridView=(GridView) this.findViewById(R.id.gridView1);        

        list.add(new Data(R.drawable.black,"0번"));
		list.add(new Data(R.drawable.blue,"1번"));
		list.add(new Data(R.drawable.green,"2번"));
		list.add(new Data(R.drawable.red,"3번"));
		list.add(new Data(R.drawable.yell,"4번"));
        
        // 2+ (3*5)
        gridView.setAdapter(new MyAdapter());
        
        //내가 click한 item의 이미지를 배경화면으로 셋팅하기
        gridView.setOnItemClickListener(
        	     new OnItemClickListener(){

					@Override
					public void onItemClick(AdapterView<?> arg0, View arg1,
							int position, long arg3) {
					Data theData=list.get(position);
					int imageId=theData.getImageId();
					
					GridViewActivity.this
					.findViewById(R.id.layout)
					.setBackgroundResource(imageId);
						
					}});
        
    }
    
    class MyAdapter extends BaseAdapter{

		@Override
		public int getCount() {			
			return list.size();
		}

		@Override
		public Object getItem(int arg0) {			
			return null;
		}

		@Override
		public long getItemId(int arg0) {			
			return 0;
		}

		@Override
		public View getView(int position, View arg1, ViewGroup arg2) {
			//item.xml을 불러오자
			LinearLayout layout=(LinearLayout)
			View.inflate(GridViewActivity.this,  //getApplicationContext();
					R.layout.item, null);
			
			//자원 list     .. list.add(new Data());
			Data oneData=list.get(position);
			
			int imageId=oneData.getImageId();
			//불러온 xml안의 ImageViwe에 이미지를 셋팅합니다
			//   ( 2*(3+5) ) -1 
			((ImageView)layout.
					findViewById(R.id.imageView1)).
					setImageResource(imageId);
			
			//불러온 xml안의 TextView에 글자를 셋팅합니다
			TextView tv=(TextView) layout.findViewById(R.id.textView1);
			tv.setText(oneData.getTitle());
			
			return layout;
		}
    	
    }
}
Data.java
package com.gusfree.gridview;

public class Data {
	private int imageId; // 이미지 주소
	private String title; //은닉화 
	
	public Data(){ //Default 생성자 Constructor
		//new Data();
	}
	
	public Data(int id, String title){//생성자 오버로딩
		//new Data(3, "dd");
		imageId=id;
		this.title=title;
	}
	
	public int getImageId(){
		return imageId;
	}
	
	public String getTitle(){ 
		// 조건 로그인했냐 .. 권한이 있냐.. 추후 ..
		return title;
	}
}




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

5일차 LogCat을 사용한 error 찾기  (0) 2012.05.02
5일차 Intent  (0) 2012.05.02
5일차 계산기  (0) 2012.05.02
5일차 계산기(내가 한것)  (0) 2012.05.02
5일차 복습  (0) 2012.05.02
<?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" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" />


    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" 
        android:textSize="30pt"/>

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/radio0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="더하기" />

        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="빼기" />

        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="곱하기" />
    </RadioGroup>

</LinearLayout>
package com.calcul;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

public class TestCalculatorActivity extends Activity {
    EditText edit1, edit2;
    TextView textView1;
	RadioGroup radioGroup;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        edit1=(EditText) findViewById(R.id.editText1);
        edit2=(EditText) findViewById(R.id.editText2);
        textView1=(TextView) findViewById(R.id.textView1);
        radioGroup=(RadioGroup) findViewById(R.id.radioGroup1);
        
        radioGroup.setOnCheckedChangeListener(
    		new OnCheckedChangeListener(){

				@Override
				public void onCheckedChanged(RadioGroup arg0, int arg1) {
					
					String one=edit1.getText().toString();
					String two=edit2.getText().toString();
					int x = Integer.parseInt(one);
					int y = Integer.parseInt(two);
					
					switch(arg1){
					case R.id.radio0:
						textView1.setText(x+y+"");
						break;
					case R.id.radio1:
						textView1.setText(x-y+"");
						break;
					case R.id.radio2:
						textView1.setText(x*y+"");
						break;
					}
					
				}});
    }
}







 내가 한거
package com.gusfree.cal;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

public class TestCalculatorActivity extends Activity {
	EditText edit1, edit2;
	TextView textView1;
	RadioGroup radioGroup;

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

		edit1=(EditText) findViewById(R.id.editText1);
		edit2=(EditText) findViewById(R.id.editText2);
		textView1=(TextView) findViewById(R.id.textView1);
		radioGroup=(RadioGroup) findViewById(R.id.radioGroup1);

		radioGroup.setOnCheckedChangeListener(
				new OnCheckedChangeListener(){

					@Override
					public void onCheckedChanged(RadioGroup arg0, int arg1) {

						//" a " -> trim() -> "a"
						//"   " -> trim() -> ""
						Editable editable1=edit1.getText();
						String one=editable1.toString().trim();
						//String one=edit1.getText().toString();

						String two=edit2.getText().toString().trim();

						/*if(one==null || one.length()<1){
							one="0";
						}
						if(one==null || one.length()<1){
							two="0";
						}*/
						
						int x = Integer.parseInt(one);
						int y = Integer.parseInt(two);

						switch(arg1){
						case R.id.radio0:
							if(x!=0 || y!=0){
								textView1.setText("더한값 "+(x+y)+"");
							}else{
								textView1.setText("정확한 값을 입력하시오");
							}
							break;
						case R.id.radio1:
							textView1.setText("뺀값 "+(x-y)+"");
							break;
						case R.id.radio2:
							textView1.setText("곱한값 "+(x*y)+"");
							break;
						}
					}
				});
	}
}




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

5일차 Intent  (0) 2012.05.02
5일차 Grid  (0) 2012.05.02
5일차 계산기(내가 한것)  (0) 2012.05.02
5일차 복습  (0) 2012.05.02
4일차 다른소스 import 하기  (1) 2012.05.01

<?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" /> <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" > </EditText> <EditText android:id="@+id/editText2" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" /> <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="80dp" android:text="합계" android:textSize="30dp"/> <RadioGroup android:id="@+id/radioGroup1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <RadioButton android:id="@+id/radio0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="더하기" /> <RadioButton android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="빼기" /> <RadioButton android:id="@+id/radio2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="곱하기" /> </RadioGroup> </LinearLayout>

package com.gusfree.cal;

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

public class TestCalculatorActivity extends Activity {
	int i, j;

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

		Button btn = (Button) findViewById(R.id.radio0);
		Button btn1 = (Button) findViewById(R.id.radio1);
		Button btn2 = (Button) findViewById(R.id.radio2);
		final TextView tv =(TextView)findViewById(R.id.textView1);

		btn.setOnClickListener(new Button.OnClickListener(){

			public void onClick(View v) {
				
				EditText one = (EditText) findViewById(R.id.editText1);
				EditText two = (EditText) findViewById(R.id.editText2);
				try {
					i = Integer.parseInt(one.getText() + "");
					j = Integer.parseInt(two.getText() + "");
				} catch (NumberFormatException e) {
					tv.setText("ㅡㅡ");
				} catch (Exception e) {
					tv.setText("아 뭐야");
				} finally {
					if(i != 0 && j != 0){
						tv.setText("+결과 : " + (i + j));
					}else{
						tv.setText("입력 하시오");
					}
				}
			}
		});
		btn1.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				EditText one = (EditText) findViewById(R.id.editText1);
				EditText two = (EditText) findViewById(R.id.editText2);
				try {
					i = Integer.parseInt(one.getText() + "");
					j = Integer.parseInt(two.getText() + "");
				} catch (NumberFormatException e) {
					tv.setText("ㅡㅡ");
				} catch (Exception e) {
					tv.setText("아 뭐야");
				} finally {
					if(i != 0 && j != 0){
						tv.setText("-결과 : " + (i - j));
					}else{
						tv.setText("입력 하시오");
					}
				}
			}
		});
		btn2.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				
				EditText one = (EditText) findViewById(R.id.editText1);
				EditText two = (EditText) findViewById(R.id.editText2);
				try {
					i = Integer.parseInt(one.getText() + "");
					j = Integer.parseInt(two.getText() + "");
				} catch (NumberFormatException e) {
					tv.setText("ㅡㅡ");
				} catch (Exception e) {
					tv.setText("아 뭐야");
				} finally {
					if(i != 0 && j != 0){
						tv.setText("*결과 : " + (i * j));
					}else{
						tv.setText("입력 하시오");
					}
				}
			}
		});
	}
}





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

5일차 Grid  (0) 2012.05.02
5일차 계산기  (0) 2012.05.02
5일차 복습  (0) 2012.05.02
4일차 다른소스 import 하기  (1) 2012.05.01
4일차 gallery2  (0) 2012.05.01
안드로이드 뷰(Context)
Layout(배치)- Linear / Relative / Frame 
Linear.addView(차일드뷰)

   <이미지뷰 />
   <버튼 /> 




   ImageView imageView=new ImageView(this);
   layout1.addView(imageView);
   layout2.addView(imageView); // 에러
   imageView.setOn~~~~
안드로이드 뷰(Context)
Layout(배치)- Linear / Relative / Frame 
Linear.addView(차일드뷰)
<LinearLayout>
   <이미지뷰 />
   <버튼 /> 


</LinearLayout>

   ImageView imageView=new ImageView(this);
   layout1.addView(imageView);
   layout2.addView(imageView); // 에러
   imageView.setOn~~~~

<Button 내이름="철수">  클릭! -> 동작 
 버튼 철수 = findViewBy이름("철수");
  리스너 l = new 리스너();
 철수.set~~~~~~  OnClickListener(l);
 버튼2.setOnClickListener(l);

 class 리스너 implements OnClickListener{
     메서드  클릭하면(나를부른 애가 누구지?){
        if(나를 부른애가==철수) {

         }
    }
 }

  체크박스/토글버튼/라디오그룹 
  .OnCheckedChangeListener  .체크가변할때호출하자(얘를)

  EditText.addTextChangedListener 글자쓰면 호출해라
     - TextWatcher 만들어주기

  어댑터! 어댑터뷰! (ListView , Spinner, Gallery)
  
  <Gallery 이름="갤러리" />
  gallery.setAdapter(new 어댑터());
 
  class 어댑터 extends BaseAdapter{
      getCount(){
     	//데이터가 몇개냐
        return 10;
      }
	 
      getView(int 몇변째작업0 ~ 9  ,   ,  ){
	그림0~그림9번
        이미지뷰( 1) 자바소스로 만들기  new
		  2) xml만들거 불러오기 inflate)
        이미지뷰에.set이미지담기(그림0);
        return 이미지뷰;
      }
  }  

  그림 데이터 
    int[] images={R.drawable.a , ....};
    ArrayList list=new ArrayList();
      list.add(R.drawable.a);
    resources폴더 value폴더 strings.xml array.xml
    <integer-array id="그림들">
	<item> 3333000009</item>
        <item> 3333000009</item>
    </integer-array>   
    
    int[] datas=       
    getResources().getIntegerArray(R.array.그림들);


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

5일차 계산기  (0) 2012.05.02
5일차 계산기(내가 한것)  (0) 2012.05.02
4일차 다른소스 import 하기  (1) 2012.05.01
4일차 gallery2  (0) 2012.05.01
4일차 gallery  (0) 2012.05.01



package Expoler에서 마우스 우측 클릭 import  Exiting Projects into Workspace 선택


다른 소스 폴더 까지 경로를 지정해준다.


Copy projects into workspace를 선택하면 workspace 안으로 import를 할 파일이 저장 된다.(안전..)


error가 나는 이유는 android.jar 파일이 없기 때문에 경로를 지정 해줌..

자신이 사용하고 있는 android를 선택


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

5일차 계산기(내가 한것)  (0) 2012.05.02
5일차 복습  (0) 2012.05.02
4일차 gallery2  (0) 2012.05.01
4일차 gallery  (0) 2012.05.01
4일차 ERROR 찾기  (0) 2012.05.01

+ Recent posts