- 메인파트
public class IntentT1 extends Activity {
    private Button b1;
    private EditText et1, et2;
    private Intent i;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        b1 = (Button)findViewById(R.id.Button01);
        et1 = (EditText)findViewById(R.id.EditText01);
        et2 = (EditText)findViewById(R.id.EditText02);
        
        //m1();
        m2();
    }
    void m1(){
    i = new Intent(this, Sub.class); //명시적 인텐트 
        
        Intent i2 = getIntent();
        String value = i2.getStringExtra("sub_key");
        et2.setText(value);
        
        b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// et1의 데이터를 뽑아서 Sub에 넘긴다.
i.putExtra("main_key", et1.getText().toString());
startActivity(i);
}
});
    }
    void m2(){
    i = new Intent(this, Sub.class); //명시적 인텐트
   
    b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// et1의 데이터를 뽑아서 Sub에 넘긴다.
i.putExtra("main_key", et1.getText().toString());
startActivityForResult(i, 0);
}
});
    }
    //Intent가 되돌아 올 때 호출되는 메소드 
    @Override
    public void onActivityResult (int requestCode, 
    int resultCode, Intent i){
    if(requestCode == 0){
    if(resultCode == RESULT_OK){
    String value = i.getStringExtra("sub_key");
           et2.setText(value);
    }
    }
    }
}

- 서브파트
 public class Sub extends Activity {
    private EditText et1, et2;
    private Button b1;
    private Intent i2;
    private Intent i; 
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sub);
        
        
        
        b1 = (Button)findViewById(R.id.Button02);
        et1 = (EditText)findViewById(R.id.EditText03);
        et2 = (EditText)findViewById(R.id.EditText04);
        
        i = getIntent();
        String value = i.getStringExtra("main_key");
        et2.setText(value);
        
        //m1();
        m2();
    }
    void m1(){
    i2 = new Intent(this, IntentT1.class);
        b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
i2.putExtra("sub_key", et1.getText().toString());
startActivity(i2);
}
});
    }
    void m2(){
    b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
i.putExtra("sub_key", et1.getText().toString());
setResult(RESULT_OK, i);
finish();
}
});
    }
}

'스마트폰 > 안드로이드' 카테고리의 다른 글

Toast 토스트 공부.  (0) 2011.05.13
Notification 공부.  (0) 2011.05.13
LifeCycle 공부.  (0) 2011.05.13
묵시적 intent 공부.  (0) 2011.05.13
이미지뷰 두번째 공부.  (0) 2011.05.13
public class LifeCycleT extends Activity 
implements View.OnClickListener {
    private Button b1, b2, b3;
    private Intent i;
    private final static String TAG = "LifeCycleT";
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.i(TAG, "onCreate()");
        
        i = new Intent(this, SubActivity.class);
        
        b1 = (Button)findViewById(R.id.Button01);
        b2 = (Button)findViewById(R.id.Button02);
        b3 = (Button)findViewById(R.id.Button03);
        
        b1.setOnClickListener(this);
        b2.setOnClickListener(this);
        b3.setOnClickListener(this);
    }
    @Override
    public void onStart(){
    super.onStart();
        Log.i(TAG, "onStart()");
    }
    @Override
    public void onResume(){
    super.onResume();
        Log.i(TAG, "onResume()");
    }
    @Override
    public void onPause(){
    super.onPause();
        Log.i(TAG, "onPause()");
    }
    @Override
    public void onStop(){
    super.onStop();
        Log.i(TAG, "onStop()");
    }
    @Override
    public void onRestart(){
    super.onRestart();
        Log.i(TAG, "onRestart()");
    }@Override
    public void onDestroy(){
    super.onDestroy();
        Log.i(TAG, "onDestroy()");
    }
    
    
    @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.Button01: dialOpen(); break;
case R.id.Button02: goSub(); break;
case R.id.Button03: finish(); break;
}
}
    void dialOpen(){
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("캠페인");
        builder.setMessage("아침밥은 먹고 다닙시다.");
        builder.setNeutralButton("확인", null);
        builder.show();
    }
    void goSub(){
    startActivity(i);
    }


public class SubActivity extends Activity 
implements View.OnClickListener {
    private Button b1, b2;
    private Intent i;
    private final static String TAG = "SubActivity";
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sub);
        Log.i(TAG, "onCreate()");
        
        i = new Intent(this, LifeCycleT.class);
        
        b1 = (Button)findViewById(R.id.Button04);
        b2 = (Button)findViewById(R.id.Button05);
        
        
        b1.setOnClickListener(this);
        b2.setOnClickListener(this);
    }
    @Override
    public void onStart(){
    super.onStart();
        Log.i(TAG, "onStart()");
    }
    @Override
    public void onResume(){
    super.onResume();
        Log.i(TAG, "onResume()");
    }
    @Override
    public void onPause(){
    super.onPause();
        Log.i(TAG, "onPause()");
    }
    @Override
    public void onStop(){
    super.onStop();
        Log.i(TAG, "onStop()");
    }
    @Override
    public void onRestart(){
    super.onRestart();
        Log.i(TAG, "onRestart()");
    }@Override
    public void onDestroy(){
    super.onDestroy();
        Log.i(TAG, "onDestroy()");
    }
    
    
    @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.Button04: goMain(); break;
case R.id.Button05: finish(); break;
}
}
    
    void goMain(){
    startActivity(i);
    }
}  

'스마트폰 > 안드로이드' 카테고리의 다른 글

Notification 공부.  (0) 2011.05.13
명시적 intent 공부.  (0) 2011.05.13
묵시적 intent 공부.  (0) 2011.05.13
이미지뷰 두번째 공부.  (0) 2011.05.13
이미지뷰(ImageView) 공부.  (0) 2011.05.13
public class ImIntentAdvanced extends Activity 
implements View.OnClickListener {
    private Button b1, b2, b3, b4, b5, b6, b7, b8, b9, b10;
    private Button b11, b12, b13, b14, b15, b16, b17, b18, b19, b20;
    private Button b21, b22, b23, b24, b25;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        init();
    }
    private void init(){
    b1 = (Button)findViewById(R.id.Button01);
    b2 = (Button)findViewById(R.id.Button02);
    b3 = (Button)findViewById(R.id.Button03);
    b4 = (Button)findViewById(R.id.Button04);
    b5 = (Button)findViewById(R.id.Button05);
   
    b6 = (Button)findViewById(R.id.Button06);
    b7 = (Button)findViewById(R.id.Button07);
    b8 = (Button)findViewById(R.id.Button08);
    b9 = (Button)findViewById(R.id.Button09);
    b10 = (Button)findViewById(R.id.Button10);
   
    b11 = (Button)findViewById(R.id.Button11);
    b12 = (Button)findViewById(R.id.Button12);
    b13 = (Button)findViewById(R.id.Button13);
    b14 = (Button)findViewById(R.id.Button14);
    b15 = (Button)findViewById(R.id.Button15);
   
    b16 = (Button)findViewById(R.id.Button16);
    b17 = (Button)findViewById(R.id.Button17);
    b18 = (Button)findViewById(R.id.Button18);
    b19 = (Button)findViewById(R.id.Button19);
    b20 = (Button)findViewById(R.id.Button20);
   
    b21 = (Button)findViewById(R.id.Button21);
    b22 = (Button)findViewById(R.id.Button22);
    b23 = (Button)findViewById(R.id.Button23);
    b24 = (Button)findViewById(R.id.Button24);
    b25 = (Button)findViewById(R.id.Button25);
   
    b1.setOnClickListener(this);
    b2.setOnClickListener(this);
    b3.setOnClickListener(this);
    b4.setOnClickListener(this);
    b5.setOnClickListener(this);
    b6.setOnClickListener(this);
    b7.setOnClickListener(this);
    b8.setOnClickListener(this);
    b9.setOnClickListener(this);
    b10.setOnClickListener(this);
    b11.setOnClickListener(this);
    b12.setOnClickListener(this);
    b13.setOnClickListener(this);
    b14.setOnClickListener(this);
    b15.setOnClickListener(this);
    b16.setOnClickListener(this);
    b17.setOnClickListener(this);
    b18.setOnClickListener(this);
    b19.setOnClickListener(this);
    b20.setOnClickListener(this);
    b21.setOnClickListener(this);
    b22.setOnClickListener(this);
    b23.setOnClickListener(this);
    b24.setOnClickListener(this);
    b25.setOnClickListener(this);
    }
    @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.Button01: m1(); break;
case R.id.Button02: m2(); break;
case R.id.Button03: m3(); break;
case R.id.Button04: m4(); break;
case R.id.Button05: m5(); break;
case R.id.Button06: m6(); break;
case R.id.Button07: m7(); break;
case R.id.Button08: m8(); break;
case R.id.Button09: m9(); break;
case R.id.Button10: m10(); break;
case R.id.Button11: m11(); break;
case R.id.Button12: m12(); break;
case R.id.Button13: m13(); break;
case R.id.Button14: m14(); break;
case R.id.Button15: m15(); break;
case R.id.Button16: m16(); break;
case R.id.Button17: m17(); break;
case R.id.Button18: m18(); break;
case R.id.Button19: m19(); break;
case R.id.Button20: m20(); break;
case R.id.Button21: m21(); break;
case R.id.Button22: m22(); break;
case R.id.Button23: m23(); break;
case R.id.Button24: m24(); break;
case R.id.Button25: m25(); break;
}
}
    
    private void m1(){ //연락처 등록
    Intent intent = new Intent(
    Intent.ACTION_INSERT, Uri.parse("content://contacts/people"));
startActivity(intent);
    }
    private void m2(){ //다이얼 화면 
    /*Intent intent = new Intent(
    Intent.ACTION_DIAL, Uri.parse("tel:01024757431"));*/
   
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_DIAL);
    intent.setData(Uri.parse("tel:01024757431"));
   
startActivity(intent);
    }
    private void m3(){ //전화 바로 걸기
    Intent intent = new Intent(
    Intent.ACTION_CALL, Uri.parse("tel:01024757431"));
startActivity(intent);
    }
    private void m4(){ //SMS발송
    Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("sms_body", "요거시 보내지는 내용이여~!");
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
    }
    private void m5(){ //이메일 발송  
    Intent intent = new Intent(
    Intent.ACTION_SENDTO, 
    Uri.parse("mailto:khs1128@gmail.com"));
startActivity(intent);
    }
    private void m6(){ //Browser에서 URL 호출하기
    Intent intent = new Intent(Intent.ACTION_VIEW,
    Uri.parse("http://www.hanmail.net/"));
startActivity(intent);
    }
    private void m7(){ //브라우저에서 검색
    Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, "검색어");
startActivity(intent);
    }
    private void m8(){ //지도 보기
    Uri uri = Uri.parse ("geo: 37.00, 128.00");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
    }
    private void m9(){ //마켓에서 특정앱 검색 
    Uri uri = Uri.parse("market://search?q=pname:soo.location.sos");  
Intent intent = new Intent(Intent.ACTION_VIEW, uri);  
startActivity(intent);  
    }
    private void m10(){ //마켓에서 상세 페이지 
    Uri uri = Uri.parse("market://details?id=soo.location.sos");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);  
startActivity(intent);
    }
    
    private void m11(){ //다른 앱(패키지)의 특정 액티비티 호출
    Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(
"soo.intent.test", "soo.intent.test.IntentT1"));
startActivity(intent);
    }
    private void m12(){ //일정표 바로 가기  
    Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(
    "com.android.calendar", 
    "com.android.calendar.LaunchActivity"));
startActivity(intent);
    }
    private void m13(){ //이메일 설정 액티비티 바로 가기
    Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(
"com.android.email", 
"com.android.email.activity.Welcome"));
    startActivity(intent);
    }
    private void m14(){ //브라우져 액티비티 띄우기 
    Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(
"com.android.browser", 
"com.android.browser.BrowserActivity"));
    startActivity(intent);
    }
    private void m15(){ //음성 검색 액티비티 호출 
    Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(
"com.google.android.voicesearch", 
"com.google.android.voicesearch.RecognitionActivity"));
    startActivity(intent);
    }
    /*
    private void m16(){ //카메라앱 호출 - 안됨 
    Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(
"com.sec.android.app.camera", 
"com.sec.android.app.camera.Camera"));
startActivity(intent);
    }
    private void m16(){ //DMB앱 호출 - 안됨  
    Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(
"com.sec.android.app.dmb", 
"com.sec.android.app.dmb.activity.DMBFullScreenView"));
startActivity(intent);
    }*/
    private void m16(){ //환경설정앱 호출  
    Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(
"com.android.settings", 
"com.android.settings.Settings"));
startActivity(intent);
    }
    /*
    private void m17(){ //작업관리자앱 호출  - 안됨 
    Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(
    "com.sec.android.app.controlpanel", 
    "com.sec.android.app.controlpanel.activity.JobManagerActivity"));
    startActivity(intent);
    }*/
    private void m17(){ //마켓 메인액티비티로  이동  
    Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(
"com.android.vending", 
"com.android.vending.AssetBrowserActivity"));
startActivity(intent);
    }
    private void m18(){
    Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(
new File(
"/sdcard/dcim/camera/2011-04-24_19-23-03_803.jpg")),
"image/jpg");
startActivity(intent);
    }
    private void m19(){
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("audio/*");
    //intent.setType("video/*");
startActivity(intent);
    }
    private void m20(){
    }
    
    private void m21(){
   
    }
    private void m22(){
   
    }
    private void m23(){
   
    }
    private void m24(){
   
    }
    private void m25(){
   
    }
}

'스마트폰 > 안드로이드' 카테고리의 다른 글

명시적 intent 공부.  (0) 2011.05.13
LifeCycle 공부.  (0) 2011.05.13
이미지뷰 두번째 공부.  (0) 2011.05.13
이미지뷰(ImageView) 공부.  (0) 2011.05.13
웹 소스 찍기  (0) 2011.05.13
public class ImageVT2 extends Activity 
implements View.OnTouchListener {
    private ImageView iv;
    
    /*private static final int IMGS[] = {
    R.drawable.ys01, R.drawable.ys02, R.drawable.ys03,
    R.drawable.ys04, R.drawable.ys05, R.drawable.ys06,
    R.drawable.ys07, R.drawable.ys08, R.drawable.ys09,
    R.drawable.ys10, R.drawable.ys11, R.drawable.ys12,
    R.drawable.ys13, R.drawable.ys14, R.drawable.ys15,
    R.drawable.ys16, R.drawable.ys17, R.drawable.ys18,
    R.drawable.ys19, R.drawable.ys20, R.drawable.ys21
    };*/
    private Field fields[] = R.drawable.class.getFields();
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        iv = (ImageView)findViewById(R.id.ImageView01);       
        iv.setOnTouchListener(this);
    }
    int i = 0;
    float x1, x2, y1, y2;
    @Override
public boolean onTouch(View v, MotionEvent event) {  
   
    if(event.getAction() == MotionEvent.ACTION_DOWN){
    x1 = event.getX();
    y1 = event.getY();
   
    //Log.i("(x1, y1)", "("+x1+", "+y1+")");
}else if(event.getAction() == MotionEvent.ACTION_UP){
x2 = event.getX();
    y2 = event.getY();
   
    //Log.i("(x2, y2)", "("+x2+", "+y2+")");
    float valueX = x1 - x2;
    if(valueX > 0){
    //if(i >= (IMGS.length-1) ) i = -1;
    if(i >= (fields.length-1) ) i = -1;
    i++;
    }else if(valueX < 0){
    //if(i <= 0) i = (IMGS.length);
    if(i <= 0) i = (fields.length);
    i--;
    }  
   
//iv.setImageResource(IMGS[i]);
    try{
    iv.setImageResource(fields[i].getInt(new Object()));
    }catch(Exception e){}
}
   
    return true;
}
}

중요한 부분 색 표시 했어요. 

'스마트폰 > 안드로이드' 카테고리의 다른 글

LifeCycle 공부.  (0) 2011.05.13
묵시적 intent 공부.  (0) 2011.05.13
이미지뷰(ImageView) 공부.  (0) 2011.05.13
웹 소스 찍기  (0) 2011.05.13
데이터 바인딩4 공부  (0) 2011.05.13
public class ImageVT extends Activity {
    /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);

     Gallery g = (Gallery) findViewById(R.id.gallery);
     g.setAdapter(new ImageAdapter(this));

     g.setOnItemClickListener(new OnItemClickListener() {
         public void onItemClick(AdapterView parent, View v, int position, long id) {
             Toast.makeText(ImageVT.this, "" + position, Toast.LENGTH_SHORT).show();
         }
     });
 }
 
 public class ImageAdapter extends BaseAdapter {
     int mGalleryItemBackground;
     private Context mContext;

     private Integer[] mImageIds = {
             R.drawable.a01,
             R.drawable.a02,
             R.drawable.a03,
             R.drawable.a04,
             R.drawable.a05,
             R.drawable.a06,
             R.drawable.a07,
             R.drawable.a08,
             R.drawable.a09,
             R.drawable.a10,
             R.drawable.a11,
             R.drawable.a12
     };

     public ImageAdapter(Context c) {
         mContext = c;
         TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
         mGalleryItemBackground = a.getResourceId(
                 R.styleable.Gallery1_android_galleryItemBackground, 0);
         a.recycle();
     }

     public int getCount() {
         return mImageIds.length;
     }

     public Object getItem(int position) {
         return position;
     }

     public long getItemId(int position) {
         return position;
     }

     public View getView(int position, View convertView, ViewGroup parent) {
         ImageView i = new ImageView(mContext);

         i.setImageResource(mImageIds[position]);
         //i.setLayoutParams(new Gallery.LayoutParams(700, 809));
         i.setScaleType(ImageView.ScaleType.FIT_CENTER);
         i.setBackgroundResource(mGalleryItemBackground);

         return i;
     }
 }
}

'스마트폰 > 안드로이드' 카테고리의 다른 글

묵시적 intent 공부.  (0) 2011.05.13
이미지뷰 두번째 공부.  (0) 2011.05.13
웹 소스 찍기  (0) 2011.05.13
데이터 바인딩4 공부  (0) 2011.05.13
데이터 바인딩3 공부  (0) 2011.05.13
public class HttpProj extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        // 웹문서 소스 출력 영역 인식
        EditText et_Webpage_src = (EditText)findViewById(R.id.webpage_src);
        
        URL url = null;
        HttpURLConnection urlConnection = null;
        BufferedInputStream buf = null;
        
        try{
        //// URL 지정과 접속
        // 웹서버 URL 지정
        url = new URL("http://www.android.com/");
        // URL 접속
        urlConnection = (HttpURLConnection)url.openConnection();
       
        //// 웹문서 소스를 버퍼에 저장
        // 데이터 다운로드
        buf = new BufferedInputStream(urlConnection.getInputStream());
        // 데이터를 버퍼에 기록
        BufferedReader bufeader = new BufferedReader(new InputStreamReader(buf, "euc-kr"));
       
        String line = null;
        String page = "";
       
        // 버퍼의 웹문서 소스를 줄 단위로 읽어(line), page에 저장함.
        while((line = bufeader.readLine()) != null){
        page += line;
        }
       
        // page 내용을 화면에 출력
        et_Webpage_src.setText(page);
        }catch(Exception e){
        et_Webpage_src.setText(e.getMessage());
        }finally{
        //URL 연결해제
        urlConnection.disconnect();
        }
        
        
    }
}

'스마트폰 > 안드로이드' 카테고리의 다른 글

이미지뷰 두번째 공부.  (0) 2011.05.13
이미지뷰(ImageView) 공부.  (0) 2011.05.13
데이터 바인딩4 공부  (0) 2011.05.13
데이터 바인딩3 공부  (0) 2011.05.13
데이터 바인딩2 공부  (0) 2011.05.13
public class DataBWT4 extends Activity {
    private GridView gv;
    static final int IMGS[] = {R.drawable.a01,
        R.drawable.a02,
        R.drawable.a03,
        R.drawable.a04,
        R.drawable.a05,
        R.drawable.a06,
        R.drawable.a07,
        R.drawable.a08,
        R.drawable.a09,
        R.drawable.a10,
        R.drawable.a11,
        R.drawable.a12
    };
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        gv = (GridView)findViewById(R.id.GridView01);
        gv.setAdapter(new UserAdapter(this));
        
        gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long arg3) {
Toast.makeText(DataBWT4.this, "선택 인덱스 : " + position, 0).show();
}
       
});
        
    }
}

class UserAdapter extends BaseAdapter{ // Controller
private Context c;
private ImageView iv;
UserAdapter(){
}
UserAdapter(DataBWT4 c){
this.c = c;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return DataBWT4.IMGS.length;
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return DataBWT4.IMGS[position];
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if(convertView == null){
iv = new ImageView(c);
iv.setLayoutParams(new GridView.LayoutParams(120,150));
//iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
iv.setScaleType(ImageView.ScaleType.FIT_XY); //크기 고정 옵션
iv.setPadding(5, 5, 15, 5);
}else{
iv = (ImageView)convertView;
}
iv.setImageResource(DataBWT4.IMGS[position]);
return iv;
}
}

'스마트폰 > 안드로이드' 카테고리의 다른 글

이미지뷰(ImageView) 공부.  (0) 2011.05.13
웹 소스 찍기  (0) 2011.05.13
데이터 바인딩3 공부  (0) 2011.05.13
데이터 바인딩2 공부  (0) 2011.05.13
데이터 바인딩1 공부  (0) 2011.05.13
package kyy.dbw.test3;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;

public class DataBWT3 extends Activity {
private Gallery g;
    static final int IMGS[] = {R.drawable.a01,
        R.drawable.a02,
        R.drawable.a03,
        R.drawable.a04,
        R.drawable.a05,
        R.drawable.a06,
        R.drawable.a07,
        R.drawable.a08,
        R.drawable.a09,
        R.drawable.a10,
        R.drawable.a11,
        R.drawable.a12
    };
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        g = (Gallery)findViewById(R.id.Gallery01); // VIEW       
        g.setAdapter(new UserAdapter(this));
        g.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long arg3) {
Toast.makeText(DataBWT3.this, "선택 인덱스 : " + position, 0).show();
}
       
});
    }
}

class UserAdapter extends BaseAdapter{ // Controller
private Context c;
private ImageView iv;
UserAdapter(){
}
UserAdapter(DataBWT3 c){
this.c = c;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return DataBWT3.IMGS.length;
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return DataBWT3.IMGS[position];
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if(convertView == null){
iv = new ImageView(c);
iv.setLayoutParams(new Gallery.LayoutParams(120, 150));
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
//iv.setScaleType(ImageView.ScaleType.FIT_XY); //크기 고정 옵션
iv.setPadding(5, 5, 15, 5);
}else{
iv = (ImageView)convertView;
}
iv.setImageResource(DataBWT3.IMGS[position]);
return iv;
}
}

'스마트폰 > 안드로이드' 카테고리의 다른 글

웹 소스 찍기  (0) 2011.05.13
데이터 바인딩4 공부  (0) 2011.05.13
데이터 바인딩2 공부  (0) 2011.05.13
데이터 바인딩1 공부  (0) 2011.05.13
anim2(애니메이션) 공부  (0) 2011.05.13

+ Recent posts