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

    <Gallery
        android:id="@+id/gallery1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:layout_weight="1"/>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, GalleryActivity!</string>
    <string name="app_name">07.Gallery</string>
    <integer-array name="images">
        <item >0x7f020000</item>
        <item >0x7f020001</item>
        <item >0x7f020002</item>
        <item >0x7f020003</item>
    </integer-array>
</resources>
/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.gusfree.gallery;

public final class R {
    public static final class array {
        public static final int images=0x7f050000;
    }
    public static final class attr {
    }
    public static final class drawable {
        public static final int a=0x7f020000;
        public static final int b=0x7f020001;
        public static final int c=0x7f020002;
        public static final int d=0x7f020003;
        public static final int ic_launcher=0x7f020004;
    }
    public static final class id {
        public static final int gallery1=0x7f060000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}

package com.gusfree.gallery;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class GalleryActivity extends Activity {
    Gallery gallery=null;
    int[] datas;
    LinearLayout layout;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.main);
        gallery=(Gallery)this.findViewById(R.id.gallery1);      
        layout=(LinearLayout)findViewById(R.id.layout);
        
        Resources res=this.getResources(); // 리소스 다가져와라
        datas=res.getIntArray(R.array.images); // 인트배열 가져와라
        gallery.setAdapter(new MyAdapter());
        
        //갤러리에 이벤트 리스너 셋팅
        gallery.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int position, long arg3) {
				//내가 보고 있는 이미지를 배경을 깔기 
				
				layout.setBackgroundResource(datas[position]);
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				
			}
		});
    }
    
    //innerClass  
    class MyAdapter extends BaseAdapter{

		@Override
		public int getCount() {			
			return datas.length; //4
		}

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

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

		@Override
		//getCount()의 리턴값만큼 실행됩니다.
		//position 0,1,2,3
		public View getView(int position, View v, ViewGroup arg2) {
			//뷰를 만들어서 AdapterView 에게 넘겨주는 역활.
			// 갤러리에서 일하는 adapter 직원이 그림4장을 받아서
			//그림을 액자에 한장씩 끼워넣고 갤러리 벽에 거는 모습
			
			int imageResId = datas[position];//그림
			ImageView imageView= new ImageView(GalleryActivity.this);//액자
			
			imageView.setImageResource(imageResId);//액자에 그림 넣기
			
			imageView.setPadding(20, 20, 20, 20);//액자에 여백 주기
			
			
			return imageView;//갤러리 벽에 액자 걸기
		}
    }
}




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

5일차 복습  (0) 2012.05.02
4일차 다른소스 import 하기  (1) 2012.05.01
4일차 gallery  (0) 2012.05.01
4일차 ERROR 찾기  (0) 2012.05.01
4일차 ImageList (textView->imageView->button-> text(Toast)출력)  (0) 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" />

    <Gallery
        android:id="@+id/gallery1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:layout_weight="1"/>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, GalleryActivity!</string>
    <string name="app_name">07.Gallery</string>
    <integer-array name="images">
        <item >0x7f020000</item>
        <item >0x7f020001</item>
        <item >0x7f020002</item>
        <item >0x7f020003</item>
    </integer-array>
</resources>
/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.gusfree.gallery;

public final class R {
    public static final class array {
        public static final int images=0x7f050000;
    }
    public static final class attr {
    }
    public static final class drawable {
        public static final int a=0x7f020000;
        public static final int b=0x7f020001;
        public static final int c=0x7f020002;
        public static final int d=0x7f020003;
        public static final int ic_launcher=0x7f020004;
    }
    public static final class id {
        public static final int gallery1=0x7f060000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}

package com.gusfree.gallery;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class GalleryActivity extends Activity {
    Gallery gallery=null;
    int[] datas;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.main);
        gallery=(Gallery)this.findViewById(R.id.gallery1);      
        
        Resources res=this.getResources(); // 리소스 다가져와라
        datas=res.getIntArray(R.array.images); // 인트배열 가져와라
        gallery.setAdapter(new MyAdapter());
    }
    
    //innerClass  
    class MyAdapter extends BaseAdapter{

		@Override
		public int getCount() {			
			return datas.length; //4
		}

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

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

		@Override
		//getCount()의 리턴값만큼 실행됩니다.
		//position 0,1,2,3
		public View getView(int position, View v, ViewGroup arg2) {
			//뷰를 만들어서 AdapterView 에게 넘겨주는 역활.
			// 갤러리에서 일하는 adapter 직원이 그림4장을 받아서
			//그림을 액자에 한장씩 끼워넣고 갤러리 벽에 거는 모습
			
			int imageResId = datas[position];//그림
			ImageView imageView= new ImageView(GalleryActivity.this);//액자
			
			imageView.setImageResource(imageResId);//액자에 그림 넣기
			
			imageView.setPadding(20, 20, 20, 20);//액자에 여백 주기
			
			return imageView;//갤러리 벽에 액자 걸기
		}
    }
}





틀림
package com.gusfree.gallery;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.Gallery;

public class GalleryActivity extends Activity {
    Gallery gallery=null;
    int[] datas;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        gallery=(Gallery)this.findViewById(R.id.gallery1);      
        setContentView(R.layout.main);
        
        //nullPointException 발생 합니다.
        gallery.setBackgroundColor(Color.BLUE);        
        
    }
}




올바른 코드
package com.gusfree.gallery;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.Gallery;

public class GalleryActivity extends Activity {
    Gallery gallery=null;
    int[] datas;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.main);
        gallery=(Gallery)this.findViewById(R.id.gallery1);      
        
        gallery.setBackgroundColor(Color.BLUE);        
        
    }
}





틀린코드
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gusfree.gallery"
    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=".GalleryActivity1"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>


올바른 코드
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gusfree.gallery"
    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=".GalleryActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>



package com.gusfree.listview;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class ImageListActivity extends Activity {
	ListView listView;
	int[] datas={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d};
	String[] contents={"둘리와 친구들","둘리","희동이","도우너"};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.listview); //inflate
		listView = (ListView) findViewById(R.id.listView1);
		MyAdapter adapter=new MyAdapter();
		listView.setAdapter(adapter);
	}
	//inner class
	class MyAdapter extends BaseAdapter{

		@Override
		public int getCount() {//데이터가 몇개냐?
			return datas.length;//4개다
		}

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

		@Override
		public long getItemId(int arg0) {
			return 0;
		}
		
		//getCount()리턴 값만큼 실행됩니다.
		//posistion 0,1,2,3
		@Override 
		public View getView(int position, View arg1, ViewGroup arg2) {
			//1.배열에서 이미지 주소를 하나씩 빼오기
			int imageRes = datas[position];
			
			//2.xml 불러오기
			LinearLayout layout=
			(LinearLayout)View.inflate(ImageListActivity.this, R.layout.item, null);
			
			//3.xml안의 ImageView 찾기
			ImageView imageView =(ImageView)layout.findViewById(R.id.imageView1);
			
			//4.그 이미지 뷰에 이미지를 세팅하기
			imageView.setImageResource(imageRes);
			
			//5.텍스트 뷰에 (찾아서)  텍스트 세팅하기
			final String text =contents[position];
			TextView textView =(TextView)layout.findViewById(R.id.textView1);
			textView.setText(text);
			
			//6.버튼을 찾아서 클릭하면 Toast로 글자 나오기
			Button btn =(Button)layout.findViewById(R.id.button1);
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View arg0) {
					Toast.makeText(ImageListActivity.this, text, 0).show();
				}});
			
			return layout;
		}
	}
}



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

4일차 gallery  (0) 2012.05.01
4일차 ERROR 찾기  (0) 2012.05.01
4일차 ImageList (SimpleAdapter, HashMap)  (2) 2012.05.01
4일차 ImageList (super class사용하는법)  (0) 2012.05.01
4일차 spinner 리스너 구현하기  (0) 2012.05.01
package com.gusfree.listview;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class ImageListActivity extends Activity {
	ListView listView;
	int[] datas={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.listview);//inflate
		listView=(ListView)findViewById(R.id.listView1);
		
		ArrayList arrayList =new ArrayList();
		
		/*HashMap오류
		 * HashMap<String,Integer> hashMap =new HashMap<String,Integer>();
		hashMap.put("image",R.drawable.a);//중복불가능
		arraylist.add(hashMap);
		hashMap.put("image",R.drawable.b);
		arraylist.add(hashMap);
		hashMap.put("image",R.drawable.c);
		arraylist.add(hashMap);
		hashMap.put("image",R.drawable.d);
		arraylist.add(hashMap); //결과가 예상과 다르게 나온다. 아래for문 으로
        */		
		for(int i=0;i<datas.length;i++){
			HashMap<String,Integer> hashMap =new HashMap<String,Integer>();
			hashMap.put("image",datas[i]);//중복불가능
			arrayList.add(hashMap);
			}
		
		/* SimpleAdapter*/
		SimpleAdapter adapter = new SimpleAdapter(this,arrayList,R.layout.item,
				new String[]{"image"},//arrayList 안의 맵의 키
				new int[]{R.id.imageView1});//R.layout.item.안의 imageView의 id
		
		listView.setAdapter(adapter);
		
		//MyAdapter adapter=new MyAdapter();
		//listView.setAdapter(adapter);
		
	}
	//inner class
	class MyAdapter extends BaseAdapter{

		@Override
		public int getCount() {//데이터가 몇개냐?
			return datas.length;//4개다
		}

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

		@Override
		public long getItemId(int arg0) {
			return 0;
		}
		
		//getCount()리턴 값만큼 실행됩니다.
		//posistion 0,1,2,3
		@Override 
		public View getView(int position, View arg1, ViewGroup arg2) {
			//1.배열에서 이미지 주소를 하나씩 빼오기
			int imageRes = datas[position];
			
			//2.xml 불러오기
			LinearLayout layout=
			(LinearLayout)View.inflate(ImageListActivity.this, R.layout.item, null);
			
			//3.xml안의 ImageView 찾기
			ImageView imageView =(ImageView)layout.findViewById(R.id.imageView1);
			
			//4.그 이미지 뷰에 이미지를 세팅하기
			imageView.setImageResource(imageRes);
			return layout;
		}
		
	}
}

주석안으로 실행시 이렇게 에러가 난다.



for문으로 실행시


Superclass사용하기~~



악...ImageListActivity로 보시길...


먼저 쓰이고 있는 ListViewActivity 앞에 "." 있어도 되고 없어도 된다.



쓰고 싶은 클래스명을 적는다..(ImageListActivity로 보인다...ㅋㅋㅋㅋ)



onCreate(Bundle)을 @Override해준다.



ListView에 ImageView를 불러올 준비를 하자~

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

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>
package com.gusfree.listview;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;

public class ImageListActivity extends Activity {
	ListView listView;
	int[] datas={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.listview);//inflate
		listView=(ListView)findViewById(R.id.listView1);
		MyAdapter adapter=new MyAdapter();
		listView.setAdapter(adapter);
		
	}
	//inner class
	class MyAdapter extends BaseAdapter{

		@Override
		public int getCount() {//데이터가 몇개냐?
			return datas.length;//4개다
		}

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

		@Override
		public long getItemId(int arg0) {
			return 0;
		}
		
		//getCount()리턴 값만큼 실행됩니다.
		//posistion 0,1,2,3
		@Override 
		public View getView(int position, View arg1, ViewGroup arg2) {
			//1.배열에서 이미지 주소를 하나씩 빼오기
			int imageRes = datas[position];
			
			//2.xml 불러오기
			LinearLayout layout=
			(LinearLayout)View.inflate(ImageListActivity.this, R.layout.item, null);
			
			//3.xml안의 ImageView 찾기
			ImageView imageview =(ImageView)layout.findViewById(R.id.imageView1);
			
			//4.그 이미지 뷰에 이미지를 세팅하기
			imageview.setImageResource(imageRes);
			return layout;
		}
		
	}
}



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

    <Spinner
        
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

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

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    
	<ListView
	    android:id="@+id/listView"
	    android:layout_width="fill_parent"
        android:layout_height="wrap_content"
	    >
	    
	    
	 </ListView>
    		
</LinearLayout>
package com.gusfree.listview;

import java.util.ArrayList;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;

public class ListViewActivity extends Activity {
	ListView listView;//서울에 사는 뽀삐
	Spinner spinner;
	ImageView imageView;
	
	//자원
	String[] datas={"티파니","써니","태연","제시카","효연","유리","윤아","서현","수영"};
	
	ArrayList arrayList =new ArrayList();//자원 사용3번째 예
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		/*listView=null;*/
		/*ListView listView;//우리동네 뽀삐*/

		arrayList.add("봄");
		arrayList.add("햇살");
		arrayList.add("시원한 물");
		arrayList.add("따뜻한 차");
		
		setContentView(R.layout.main);//이후에 findView
		listView=(ListView)findViewById(R.id.listView);
		spinner=(Spinner)this.findViewById(R.id.spinner1);
		imageView=(ImageView)findViewById(R.id.imageView1);
		
		/* Context 뷰를 올릴 수 있는 뒤쪽의 ....
		 * Android-Context
		 * Web-'2d'Graphics
		 * Java - frame*/
		ArrayAdapter sAdapter=
				ArrayAdapter.createFromResource(
						ListViewActivity.this, R.array.girls, 
						android.R.layout.simple_spinner_item);
		
		//spinner 클릭 했을때 펼처지는 뷰에 사용할 layout
		sAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner.setAdapter(sAdapter);
		
		//spinner리스너 구현하기
		spinner.setOnItemSelectedListener(new OnItemSelectedListener(){

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				Toast.makeText(ListViewActivity.this,
						arg2+" ,"+arg3, 0).show();
				
				/* class Toast{
				 * 		static String LENGTH_SHORT=0;
				 * 		static String LENGTH_LONG=1;
				 * */
				switch(arg2){
				case 0:
					imageView.setImageResource(R.drawable.tipa);
					break;
				case 1:
					imageView.setImageResource(R.drawable.sun);
					break;
				case 2:
					imageView.setImageResource(R.drawable.tae);
					break;
				case 3:
					imageView.setImageResource(R.drawable.je);
					break;
				case 4:
					imageView.setImageResource(R.drawable.hyu);
					break;
				case 5:
					imageView.setImageResource(R.drawable.uri);
					break;
				case 6:
					imageView.setImageResource(R.drawable.unna);
					break;
				case 7:
					imageView.setImageResource(R.drawable.seo);
					break;
				case 8:
					imageView.setImageResource(R.drawable.su);
					break;
					
				}
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				//라디오 그룹에서는 호출될 일이 없다.
			}});
		
		//res폴더안에 있는 거 전부 가져오기
		Resources res = getResources();

		//어뎁터
		/* 110v 가전제품   - 어댑터 -    220v
                  일본 가전제품 110v  <- 어댑터  <- 220v 전원
           ListView  <-  Adapter  <-  화면에 표시할 데이터 
        			                                 스트링 배열*/
		//어뎁터 생성
		ArrayAdapter<String> adapter = 
				new ArrayAdapter<String>(this, 
						android.R.layout.simple_list_item_1,
						R.array.girls);
						//arrayList);
						//res.getStringArray(R.array.girls));
						//datas);
		//set adapter
		listView.setAdapter(adapter);

		//set item Click
		listView.setOnItemClickListener(new OnItemClickListener(){

			@Override//리스너를 호출한 뷰의 정보가 넘어옵니다.
			public void onItemClick(AdapterView<?> 
			arg0,View arg1, int arg2,long arg3) {
				//arg0 = listView
				//arg1 = TextView		
				//arg2 = 포지션값		
				
				//리스튜 뷰의 x번째 아이템 값을 가져와라
				String msg=(String)listView.getItemAtPosition(arg2);
				
				//간단하게 메시지를 표시해주는 용도로 사용
				Toast toast =null;//튀어나오는 뷰
				toast = toast.makeText(getApplicationContext(), 
						arg2+" 번째 "+msg, Toast.LENGTH_SHORT);
				toast.show();//화면에 나와라
						
			}
		});
	}
}





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

    <Spinner
        
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    
	<ListView
	    android:id="@+id/listView"
	    android:layout_width="fill_parent"
        android:layout_height="wrap_content"
	    >
	    
	    
	 </ListView>
    		
</LinearLayout>
package com.gusfree.listview;

import java.util.ArrayList;

import android.R.string;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;

public class ListViewActivity extends Activity {
	ListView listView;//서울에 사는 뽀삐
	Spinner spinner;
	
	//자원
	String[] datas={"티파니","써니","태연","제시카","효연","유리","윤아","서현","수영"};
	
	ArrayList arrayList =new ArrayList();//자원 사용3번째 예
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		/*listView=null;*/
		/*ListView listView;//우리동네 뽀삐*/

		arrayList.add("봄");
		arrayList.add("햇살");
		arrayList.add("시원한 물");
		arrayList.add("따뜻한 차");
		
		setContentView(R.layout.main);//이후에 findView
		listView=(ListView)findViewById(R.id.listView);
		spinner=(Spinner)this.findViewById(R.id.spinner1);
		
		/* Context 뷰를 올릴 수 있는 뒤쪽의 ....
		 * Android-Context
		 * Web-'2d'Graphics
		 * Java - frame*/
		ArrayAdapter sAdapter=
				ArrayAdapter.createFromResource(
						ListViewActivity.this, R.array.girls, 
						android.R.layout.simple_spinner_item);
		
		//spinner 클릭 했을때 펼처지는 뷰에 사용할 layout
		sAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner.setAdapter(sAdapter);
		
		
		//res폴더안에 있는 거 전부 가져오기
		Resources res = getResources();

		//어뎁터
		/* 110v 가전제품   - 어댑터 -    220v
                  일본 가전제품 110v  <- 어댑터  <- 220v 전원
           ListView  <-  Adapter  <-  화면에 표시할 데이터 
        			                                 스트링 배열*/
		//어뎁터 생성
		ArrayAdapter<String> adapter = 
				new ArrayAdapter<String>(this, 
						android.R.layout.simple_list_item_1,
						R.array.girls);
						//arrayList);
						//res.getStringArray(R.array.girls));
						//datas);
		//set adapter
		listView.setAdapter(adapter);

		//set item Click
		listView.setOnItemClickListener(new OnItemClickListener(){

			@Override//리스너를 호출한 뷰의 정보가 넘어옵니다.
			public void onItemClick(AdapterView<?> 
			arg0,View arg1, int arg2,long arg3) {
				//arg0 = listView
				//arg1 = TextView		
				//arg2 = 포지션값		
				
				//리스튜 뷰의 x번째 아이템 값을 가져와라
				String msg=(String)listView.getItemAtPosition(arg2);
				
				//간단하게 메시지를 표시해주는 용도로 사용
				Toast toast =null;//튀어나오는 뷰
				toast = toast.makeText(getApplicationContext(), 
						arg2+" 번째 "+msg, Toast.LENGTH_SHORT);
				toast.show();//화면에 나와라
						
			}
		});
	}
}






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

    <ListView
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
   
    </ListView>


</LinearLayout>
package com.gusfree.listview;

import java.util.ArrayList;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListViewActivity extends Activity {
	ListView listView;//서울에 사는 뽀삐

	//자원
	String[] datas={"티파니","써니","태연","제시카","효연","유리","윤아","서현","수영"};
	
	ArrayList arrayList =new ArrayList();//자원 사용3번째 예
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		/*listView=null;*/
		/*ListView listView;//우리동네 뽀삐*/

		arrayList.add("봄");
		arrayList.add("햇살");
		arrayList.add("시원한 물");
		arrayList.add("따뜻한 차");
		
		setContentView(R.layout.main);//이후에 findView
		listView=(ListView)findViewById(R.id.listView);

		//res폴더안에 있는 거 전부 가져오기
		Resources res = getResources();

		//어뎁터
		/* 110v 가전제품   - 어댑터 -    220v
                  일본 가전제품 110v  <- 어댑터  <- 220v 전원
           ListView  <-  Adapter  <-  화면에 표시할 데이터 
        			                                 스트링 배열*/
		//어뎁터 생성
		ArrayAdapter<String> adapter = 
				new ArrayAdapter<String>(this, 
						android.R.layout.simple_list_item_1,
						arrayList);
						//res.getStringArray(R.array.girls));
						//datas);
		//set adapter
		listView.setAdapter(adapter);

		//set item Click
		listView.setOnItemClickListener(new OnItemClickListener(){

			@Override//리스너를 호출한 뷰의 정보가 넘어옵니다.
			public void onItemClick(AdapterView<?> 
			arg0,View arg1, int arg2,long arg3) {
				//arg0 = listView
				//arg1 = TextView		
				//arg2 = 포지션값		
				
				//리스튜 뷰의 x번째 아이템 값을 가져와라
				String msg=(String)listView.getItemAtPosition(arg2);
				
				//간단하게 메시지를 표시해주는 용도로 사용
				Toast toast =null;//튀어나오는 뷰
				toast=toast.makeText(getApplicationContext(), arg2+" 번째 "+msg, Toast.LENGTH_SHORT);
				toast.show();//화면에 나와라
						
			}
		});
	}
}




values->strings.xml 클릭



add를 클릭한다.


String Array를 클릭하고 ok



화면 우측 상단에 Attributes for String Array 필드 Name에 객체명을 지정해준다.


헉 girlsgeneration으로 나오는데 너무길어서 다시girls로 바꿨다..ㅋㅋㅋ

아무튼 girls 누르고 add item을 누른다.


그럼 Array값을 적어 주기 시작한다.(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" />

    <ListView
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
   
    </ListView>


</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, ListViewActivity!</string>
    <string name="app_name">06.ListView</string>
    <string-array name="girls">
        <item >티파니</item>
        <item >써니</item>
        <item >태연</item>
        <item >제시카</item>
        <item >효연</item>
        <item >유리</item>
        <item >윤아</item>
        <item >서현</item>
        <item >수영</item>
    </string-array>
	
</resources>
package com.gusfree.listview;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListViewActivity extends Activity {
	ListView listView;//서울에 사는 뽀삐

	//자원
	String[] datas={"티파니","써니","태연","제시카","효연","유리","윤아","서현","수영"};
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		/*listView=null;*/
		/*ListView listView;//우리동네 뽀삐*/

		setContentView(R.layout.main);//이후에 findView
		listView=(ListView)findViewById(R.id.listView);

		//res폴더안에 있는 거 전부 가져오기
		Resources res = getResources();


		//어뎁터
		/* 110v 가전제품   - 어댑터 -    220v
            일본 가전제품 110v  <- 어댑터  <- 220v 전원
           ListView  <-  Adapter  <-  화면에 표시할 데이터 
        			                         스트링 배열*/
		//어뎁터 생성
		ArrayAdapter<String> adapter = 
				new ArrayAdapter<String>(this, 
						android.R.layout.simple_list_item_1,
						res.getStringArray(R.array.girls));
		//set adapter
		listView.setAdapter(adapter);

		//set item Click
		listView.setOnItemClickListener(new OnItemClickListener(){

			@Override//리스너를 호출한 뷰의 정보가 넘어옵니다.
			public void onItemClick(AdapterView<?> 
			arg0,View arg1, int arg2,long arg3) {
				//arg0 = listView
				//arg1 = TextView		
				//arg2 = 포지션값		

				//리스트 뷰의 x번째 아이템 값을 가져와라
				String msg=(String)listView.getItemAtPosition(arg2);

				//간단하게 메시지를 표시해주는 용도로 사용
				Toast toast =null;//튀어나오는 뷰
				toast=toast.makeText(getApplicationContext(), arg2+" 번째 "+
						msg, Toast.LENGTH_SHORT);
				toast.show();//화면에 나와라

			}
		});
	}
}



Adapter의 역할

데이터를 한 단위씩 나누어서 
getView *10회
return 뷰 *10회=> ListView 10줄 완성
<?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" />

    <ListView
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
   
    </ListView>


</LinearLayout>
package com.gusfree.listview;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListViewActivity extends Activity {
	ListView listView;//서울에 사는 뽀삐
	
	//자원
	String[] datas={"티파니","써니","태연","제시카","효연","유리","윤아","서현","수영"};
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        /*listView=null;*/
        /*ListView listView;//우리동네 뽀삐*/
        
        setContentView(R.layout.main);//이후에 findView
        listView=(ListView)findViewById(R.id.listView);
        
        //어뎁터
        /* 110v 가전제품   - 어댑터 -    220v
                  일본 가전제품 110v  <- 어댑터  <- 220v 전원
           ListView  <-  Adapter  <-  화면에 표시할 데이터 
        			                                 스트링 배열*/
       
        ArrayAdapter<String> adapter = 
        		new ArrayAdapter<String>(this, 
        				android.R.layout.simple_list_item_1,datas);
        //set adapter
        listView.setAdapter(adapter); 
    }
}


사용하면 좋다...
TextView - OnClick
EditText - .addTextChangeListener(TextWatcher)
CheckBox - .setOnChekcedChangedListener()
RadioGroup - .setOnCheckdChangedListener()
ToggleButton - .setOnChekcedChangedListener()
Button - .setOnClickListener
<?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:background="@drawable/weather"
    android:id="@+id/ll"
    >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="TextView Demo"
        android:textColor="#ffffff"
        android:textSize="13px"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:autoLink="web|email|phone|map"
        android:text="" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="input your name!"
       
         >
    </EditText>

    <ImageButton
        android:contentDescription="버튼이미지" 
        android:id="@+id/imageButton1"
        android:layout_width="10mm"
        android:layout_height="10mm"
        android:src="@drawable/weather" />

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ToggleButton
        android:text="토글버튼"
        android:textOn="ON"
        android:textOff="OFF"
        android:id="@+id/toggleButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         />

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="email수신여부" />

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
         >
        <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="여자" />
    </RadioGroup>

</LinearLayout>
package com.gusfree.lisenter2;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.ToggleButton;

public class Lisetner2Activity extends Activity {
	/** Called when the activity is first created. */
	EditText et1;
	TextView tv1;
	TextView tv2;
	ImageButton ib; 
	ToggleButton tb;
	ProgressBar pb;
	CheckBox cb;
	RadioGroup rg;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		et1 = (EditText) findViewById(R.id.editText1);
		tv1 = (TextView) findViewById(R.id.textView1);
		tv2 = (TextView) findViewById(R.id.textView2);
		ib = (ImageButton) this.findViewById(R.id.imageButton1);
		tb = (ToggleButton) findViewById(R.id.toggleButton1);
		pb = (ProgressBar) findViewById(R.id.progressBar1);
		cb = (CheckBox) findViewById(R.id.checkBox1);
		rg = (RadioGroup) findViewById(R.id.radioGroup1);
		// event
		ib.setOnClickListener(new ImageButtonHandler());
		tb.setOnCheckedChangeListener(new ToggleButtonHandler());
		cb.setOnCheckedChangeListener(new CheckBoxHandler());
		rg.setOnCheckedChangeListener(new RadioButtonHandler());
		et1.addTextChangedListener(new EditTextHandler());
		
		
		Resources res=this.getResources();
		String tc=res.getString(R.string.hello);
		tv2.setText(tc);
		 
		
	}
	/*******EditText***************/
	public class EditTextHandler implements TextWatcher{

		public void afterTextChanged(Editable arg0) {
		}

		public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
				int arg3) {
			// TODO Auto-generated method stub
			
		}
		public void onTextChanged(CharSequence arg0, int arg1, int arg2,
				int arg3) {
			tv2.setText(arg0);
			
		}
		
	}
	
	
	/******** RadioGroup *******/
	public class RadioButtonHandler implements
			android.widget.RadioGroup.OnCheckedChangeListener {

		public void onCheckedChanged(RadioGroup group, int checkedId) {
			LinearLayout ll=(LinearLayout)findViewById(R.id.ll);
			if (checkedId == R.id.radio0) {
				// 남자그림배경
				ll.setBackgroundResource(R.drawable.phi);
			} else if (checkedId == R.id.radio1) {
				// 여자그림배경
				ll.setBackgroundResource(R.drawable.iyou);
			}
		}
	}

	/********** CheckBox ****************************/
	public class CheckBoxHandler implements OnCheckedChangeListener {

		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {
			if (isChecked) {
				buttonView.setText("email수신여부[체크]");
			} else {
				buttonView.setText("email수신여부[안체크]");
			}

		}

	}

	/************ ToggleButton *********************/
	public class ToggleButtonHandler implements OnCheckedChangeListener {

		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {
			if (isChecked) {
				// progress bar
				pb.setVisibility(View.VISIBLE);
			} else {
				pb.setVisibility(View.INVISIBLE);

			}

		}

	}

	/************* ImageButton ********************/

	public class ImageButtonHandler implements OnClickListener {
		boolean b = false;

		public void onClick(View v) {
			/*
			 * Editable android.widget.EditText.getText()
			 */
			String str = et1.getText().toString();
			tv1.setText(str);
			et1.setText("");
			/** image 변경 **/
			b = !b;
			if (b) {
				ib.setImageResource(R.drawable.weather);
			} else {
				ib.setImageResource(R.drawable.koreanfood);
			}

		}

	}
}



<?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:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />

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

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CheckBox" />

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

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

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

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

</LinearLayout>
package com.listener;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.ToggleButton;

public class ListenerActivity extends Activity {

	LinearLayout layout;
	TextView textView;
	EditText editText;
	CheckBox checkBox;
	RadioGroup radioGroup;
	ToggleButton toggleButton;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		layout=(LinearLayout) findViewById(R.id.layout);
		textView=(TextView) findViewById(R.id.textView1);
		editText = (EditText) this.findViewById(R.id.editText1);
		checkBox = (CheckBox) findViewById(R.id.checkBox1);
		radioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
		toggleButton = (ToggleButton) findViewById(R.id.toggleButton1);
		/*체크박스&토글버튼&라디오그룹 : CheckedChange
		 * 라디오그룹 : ItemSeleced
		 * 텍스트뷰 : ClickListener
		 * layout : ClickListener
		 * editText : addTextWatcher*   */      

		/*리스너 클래스들의 객체를 만들고 
        뷰에 만든 리스너 객체를 셋팅하세요 */
		/*checkBox.setOnCheckedChangeListener(new CheckedChangeListener());
        toggleButton.setOnCheckedChangeListener(new CheckedChangeListener());
        radioGroup.setOnCheckedChangeListener(new RadioListener());
        editText.addTextChangedListener(new EditListener());
        layout.setOnClickListener(new ClickListener());
        textView.setOnClickListener(new ClickListener());*/

		toggleButton.setOnCheckedChangeListener(new T());
		checkBox.setOnCheckedChangeListener(new T());
		radioGroup.setOnCheckedChangeListener(new RG());
		editText.addTextChangedListener(new E());
	}
	class E implements TextWatcher{
		@Override
		public void onTextChanged(CharSequence s, int start, int before,
				int count) {			
			textView.setText(s);
		}
		@Override
		public void afterTextChanged(Editable s) {			
		}
		@Override
		public void beforeTextChanged(CharSequence s, int start, int count,
				int after) {
		}
	}
	class RG implements android.widget.RadioGroup.OnCheckedChangeListener{
		@Override
		public void onCheckedChanged(RadioGroup group, int checkedId) {
			switch(checkedId){
			case R.id.radio0:
				layout.setBackgroundColor(Color.WHITE);
				break;
			case R.id.radio1:
				layout.setBackgroundColor(Color.BLACK);
				break;
			case R.id.radio2:
				layout.setBackgroundColor(Color.GRAY);
				break;
			}
		}
	}
	class T implements OnCheckedChangeListener{

		@Override//토글버튼
		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {
			if(buttonView==toggleButton){

			}
			if(isChecked){
				layout.setBackgroundResource(R.drawable.sosi);
			}else{
				layout.setBackgroundResource(R.drawable.sosii);
			}

		}

		/*//textView, layout
    class ClickListener implements OnClickListener{

		@Override
		public void onClick(View v) {


		}    	
    }
    //toggleButton, checkBox 용
    class CheckedChangeListener 
    	implements OnCheckedChangeListener{
    	// 개똥이
		@Override
		public void onCheckedChanged(
				CompoundButton buttonView,
				boolean isChecked) {			
		}    	
    }
    //radioGroup 용
    class RadioListener implements 
    android.widget.RadioGroup.OnCheckedChangeListener{
    	//한국의 대구에 사는 개똥이
		@Override
		public void onCheckedChanged(RadioGroup group,
				int checkedId) {
		}
    }
    //editText용 
    class EditListener implements TextWatcher {
		@Override
		public void afterTextChanged(Editable s) {
		}
		@Override
		public void beforeTextChanged(CharSequence s, int start, int count,
				int after) {
		}
		@Override
		public void onTextChanged(CharSequence s, int start, int before,
				int count) {
		}*/
	}
}



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

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/dolly" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Large Text"
            android:textColor="#cc0000"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </FrameLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ToggleButton
            android:id="@+id/toogleButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <ToggleButton
            android:id="@+id/toogleButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

</LinearLayout>
package com.gusfree;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;

public class LayoutActivity extends Activity 
					implements OnClickListener{
    TextView textView; //클래스 변수 선언
    ImageView imageView;
    ToggleButton toggle1, toggle2;
    
    @Override   
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.frame);
        
        textView=(TextView) findViewById(R.id.textView1);
        imageView = (ImageView) findViewById(R.id.imageView1);
        toggle1=(ToggleButton) findViewById(R.id.toogleButton1);
        toggle2=(ToggleButton) findViewById(R.id.toogleButton2);
       
        toggle1.setOnClickListener(this);
        toggle2.setOnClickListener(this);
        
        MyListener myListener=new MyListener();
        //토글버튼의 Checked가 Change 될때 호출되는 Listener
        toggle1.setOnCheckedChangeListener(myListener);
        toggle2.setOnCheckedChangeListener(myListener);
    } 
    
    class MyListener implements OnCheckedChangeListener{
    	
    	//파라미터1 : 나를 부른뷰.. 파라미터2: 뷰의 체크상태
		@Override
		public void onCheckedChanged(
				CompoundButton v, boolean checked) {
			if(v==toggle1){ 
				if(checked) imageView.setVisibility(View.VISIBLE);
				else imageView.setVisibility(View.GONE);
			}
			// 토글버튼2의 체크상태에 따라 textView가 보였다 안보였다
			else if(v==toggle2){
				if(checked)textView.setVisibility(View.VISIBLE);
				else  textView.setVisibility(View.GONE);
			}
			
		}
    	
    }
    
    /*Listener의 특징 : 파라미터로 리스너를 호출한 뷰가
     * 넘어옵니다     */
	@Override
	public void onClick(View v) {	
		
		/*if(v == toggle1)	{	
			textView.setText("토글버튼1 눌렀다");
			imageView.setVisibility(View.VISIBLE); //static 필드
		}
		else if(v == toggle2){
			textView.setText("토글버튼2 눌렀다");
			imageView.setVisibility(View.INVISIBLE); //static 필드
		}*/
	}
	
	
	
	class A implements OnClickListener{
		
		@Override
		public void onClick(View arg0) {
			
			
		}
		
	}
}







<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:layout_marginBottom="150dp">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/dolly" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="텍스트뷰 텍스트뷰 텍스트뷰 텍스트뷰"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</FrameLayout>



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

3일차 다양한 이벤트 처리(미완성)  (0) 2012.04.30
3일차 LinearLayout( frame 중복)  (0) 2012.04.30
3일차 Layout3 화면정의  (0) 2012.04.30
3일차 1~45 까지 로또  (0) 2012.04.30
Android review  (0) 2012.04.30

+ Recent posts