레이블이 Android인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Android인 게시물을 표시합니다. 모든 게시물 표시

2011년 3월 30일 수요일

Failed to install user.apk on device 'Mxxxxxxx': timeout

Window -> Preferences -> android -> ddms -> ADB COnnection time out (ms) 를 5000에서 10000이상으로 올려주면 된다.

2011년 3월 13일 일요일

Couldn't get connection factory client

1. 실행에 들어가서 cmd를 실행해서 콘솔창을 띄운다.

2. cmd창의 경로를 아래와 같이 이동합니다.(전 윈7이며 제컴퓨터 기준으로 한거랍니다.)
C:\Users\mycomputer\.android

3. 아래 명령어를 입력한다.
keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android


4. 나온 인증서지문(MD5)를 복사한다.


5. http://code.google.com/intl/ko-KR/android/maps-api-signup.html 페이지에 가서 동의를 클릭하고 복사한 인증서 지문을 붙여넣어 오케이 한다.

2010년 5월 22일 토요일

Spinner : Changing Header Text Color

1) main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 >
 <TextView
  android:id="@+id/selector"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
 
  />
 <Spinner android:id="@+id/spinner"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:drawSelectorOnTop="true"/>
</LinearLayout>

 

2) SpinnerDemo.java

package com.commonsware.android.selection;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

public class SpinnerDemo extends Activity
 implements AdapterView.OnItemSelectedListener {
 TextView selection;
 String[] items={"a", "b", "c", "d", "e",
     "e", "f", "g", "h", "i",
     "j", "k", "l", "james", "m"};
 
 @Override
 public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.main);
  selection=(TextView)findViewById(R.id.selector);
 
  Spinner spin=(Spinner)findViewById(R.id.spinner);
 
  spin.setOnItemSelectedListener(this);
 
  ArrayAdapter<String> aa=new ArrayAdapter<String>(this,
               android.R.layout.simple_spinner_item,
               items);
 
  aa.setDropDownViewResource(
   android.R.layout.simple_spinner_dropdown_item);

  spin.setAdapter(aa);
 }
 
 public void onItemSelected(AdapterView<?> parent,
                View v, int position, long id) {
  selection.setText(items[position]);
  ((TextView)parent.getChildAt(0)).setTextColor(Color.RED);

// Of cause, This source is abailable for index number more than 0.
 }
 
 public void onNothingSelected(AdapterView<?> parent) {
  selection.setText("");
 }
}

 

 

 

 















































Reference source : http://apress.com

2010년 4월 26일 월요일

From javascript to java, From Java to javascript

 

 

Reference http://www.itcpub.co.kr

Access SDCard

C:\>mksdcard 256M c:\sd.img

C:\>dir c:\sd.img
 C 드라이브의 볼륨에는 이름이 없습니다.
 볼륨 일련 번호: D88A-40A9

 c:\ 디렉터리

2010-04-27  오전 09:49       268,435,456 sd.img
               1개 파일         268,435,456 바이트
               0개 디렉터리  68,453,728,256 바이트 남음

 

 

 

 

 

 

数独




























































































































































































































2010년 4월 14일 수요일

Weather Program

1) Class Diagram

2) Widget Images

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

3) Google Weather API example

http://www.google.co.uk/ig/api?weather=london

<?xml version="1.0" ?>

- <xml_api_reply version="1">
- <weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
- <forecast_information>
  <city data="London, England" />
  <postal_code data="london" />
  <latitude_e6 data="" />
  <longitude_e6 data="" />
  <forecast_date data="2010-04-14" />
  <current_date_time data="2010-04-14 05:20:00 +0000" />
  <unit_system data="SI" />
  </forecast_information>
- <current_conditions>
  <condition data="대체로 흐림" />
  <temp_f data="45" />
  <temp_c data="7" />
  <humidity data="습도: 76%" />
  <icon data="/ig/images/weather/mostly_cloudy.gif" />
  <wind_condition data="바람: 북풍, 11 km/h" />
  </current_conditions>
.
.
 

2010년 4월 13일 화요일

Writing Real-Time Games for Android

From http://www.androidside.com/

Use SurfaceView

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1) /MyGraphics2D02/src/my/MyGraphics2D02/MyGraphics2D02.java

package my.MyGraphics2D02;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;

public class MyGraphics2D02 extends Activity {
 
 class GraphicIcon { // 새로운 비트맵 아이콘들을 생성하기 위한 클래스를 추가
        private Bitmap bm;
        private Coordinates co; // 좌표처리
    
        public GraphicIcon(Bitmap bitmap) {
            bm = bitmap;
            co = new Coordinates();
        }
    
        public Bitmap getGraphic() {
            return bm;
        }
    
        public Coordinates getCoordinates() {
            return co;
        }
    
      
        public class Coordinates {
            private int x = 0;
            private int y = 0;
    
            public int getX() {
                return x;
            }
    
            public void setX(int value) {
                x = value - bm.getWidth() / 2;
            }
    
            public int getY() {
                return y;
            }
    
            public void setY(int value) {
                y = value - bm.getHeight() / 2;
            } 
          
        }
    }
 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Enable extended window features. This is a convenience for calling getWindow().requestFeature().
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(new CustomView(this));
    }
 
    class CustomView extends SurfaceView implements SurfaceHolder.Callback {
        private CustomViewThread CVThread;
        // ArrayList Graphics는 GraphicIcon클래스를 사용해 생성한 객체들을 저장
        private ArrayList<GraphicIcon> graphics = new ArrayList<GraphicIcon>();
        private int x = 70;
        private int y = 70;

        public CustomView(Context context) {
            super(context);
            getHolder().addCallback(this);
            CVThread = new CustomViewThread(getHolder(), this);
            setFocusable(true); // 해당  View가 touch mode에서 Focus가 가도록 지정합니다.
        }
 
        @Override
        public void onDraw(Canvas canvas) {
       
         Bitmap bm;
            canvas.drawColor(Color.parseColor("#dedede"));
            GraphicIcon.Coordinates co;
            // For문 : ArrayList graphics에 들어 있는 객체들을 하나씩 꺼내어 graphic변수에 저장하여 그림을 그림.
            for (GraphicIcon graphic : graphics) {
                bm = graphic.getGraphic();
                co = graphic.getCoordinates();
                canvas.drawBitmap(bm, co.getX(), co.getY(), null);
            }
        }
 
        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
            // TODO Auto-generated method stub
 
        }
 
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            CVThread.setRunning(true);
            CVThread.start();
        }
 
        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
           
            boolean retry = true;
            CVThread.setRunning(false);
            while (retry) {
                try {
                    CVThread.join();
                    retry = false;
                } catch (InterruptedException e) {
                   
                }
            }
        }
       
        public boolean onTouchEvent(MotionEvent event) {
         synchronized (CVThread.getSurfaceHolder()) { // ConcurrentModificationException 처리
          if(event.getAction()==MotionEvent.ACTION_DOWN){ //드레그해도 연속으로 생성되지 않게 함.
           GraphicIcon graphic = new GraphicIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
              graphic.getCoordinates().setX((int) event.getX());
              graphic.getCoordinates().setY((int) event.getY());
              graphics.add(graphic);
          }
          return true;
         }
        }


    }
 
    class CustomViewThread extends Thread {
        private SurfaceHolder surfaceholder;
        private CustomView customview;
        private boolean running = false;
        public SurfaceHolder getSurfaceHolder() {
            return surfaceholder;
        }

        public CustomViewThread(SurfaceHolder surfaceHolder, CustomView CustomView) {
            surfaceholder = surfaceHolder;
            customview = CustomView;
        }
 
        public void setRunning(boolean run) {
            running = run;
        }
 
        @Override
        public void run() {
            Canvas c;
            while (running) {
                c = null;
                try {
                    c = surfaceholder.lockCanvas(null);
                    synchronized (surfaceholder) {
                        customview.onDraw(c);
                    }
                } finally {
                   
                    if (c != null) {
                        surfaceholder.unlockCanvasAndPost(c);
                    }
                }
            }
        }
    }
}

2) Result image

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Reference http://www.androidside.com

2010년 4월 12일 월요일

Google MapView in Android

1) System confirm path

내컴퓨터 > 고급 > 환경변수 > path >

Add this path :

C:\android\tools;C:\Program Files\Java\jdk1.6.0_17\bin

 

2) Get the API Key

C:\>cd C:\Documents and Settings\%username%\.android\

C:\Documents and Settings\jp\.android>keytool -list -alias androiddebugkey -keys
tore debug.keystore -storepass android -keypass android
androiddebugkey, 2010. 4. 12, PrivateKeyEntry,
인증서 지문(MD5): B1:B9:5F:01??????????????????:27:BF:29:FA:67:5C:26

 

http://code.google.com/intl/ko/android/maps-api-signup.html

Sign Up for the Android Maps API

 

 

3) Create AVD

over level Google APIs Level 6

 

4) Create project

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5) /HelloMyMap/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="my.HelloMyMap"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-permission android:name="android.permission.INTERNET" /> 
    <application android:icon="@drawable/icon" android:label="@string/app_name">
     <uses-library android:name="com.google.android.maps" />
        <activity android:name=".HelloMyMap"
                  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>
    <uses-sdk android:minSdkVersion="6" />

</manifest>

 

6) /HelloMyMap/res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainlayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <com.google.android.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:apiKey="00Q8dPkiSL???????????????v-PfctrXmOFA"
    />
       
</RelativeLayout>

 

7) /HelloMyMap/src/my/HelloMyMap/HelloItemizedOverlay.java

package my.HelloMyMap;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class HelloItemizedOverlay extends ItemizedOverlay {
 private Context mContext;
 private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
 
 public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
    super(boundCenterBottom(defaultMarker));
    // TODO Auto-generated constructor stub
    mContext = context;
   }

  @Override
  protected OverlayItem createItem(int i) {
   // TODO Auto-generated method stub
   return mOverlays.get(i);
  }

  @Override
  public int size() {
   // TODO Auto-generated method stub
   return  mOverlays.size();
  }
 
  public void addOverlay(OverlayItem overlay) {
      mOverlays.add(overlay);
      populate();
  }
 
  @Override
  protected boolean onTap(int index) {
    OverlayItem item = mOverlays.get(index);
    AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
    dialog.setTitle(item.getTitle());
    dialog.setMessage(item.getSnippet());
    dialog.show();
    return true;
  }

}

8) /HelloMyMap/src/my/HelloMyMap/HelloMyMap.java

package my.HelloMyMap;

import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.ZoomControls;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class HelloMyMap extends MapActivity {
 
  List<Overlay> mapOverlays;
  Drawable drawable;
  HelloItemizedOverlay itemizedOverlay;
  LinearLayout linearLayout;
  MapView mapView;
  ZoomControls mZoom;

 @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
 
/** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mapView.setSatellite(false);
       
        GeoPoint p=new GeoPoint(53458671,-2267346);
        MapController mc=mapView.getController();       
        mc.animateTo(p);
        mc.setZoom(5);
       
        mapOverlays = mapView.getOverlays();
        drawable = this.getResources().getDrawable(R.drawable.androidmarker);
        itemizedOverlay = new HelloItemizedOverlay(drawable,this);
       
        OverlayItem overlayitem = new OverlayItem(p, "Hello", "Man Utd.");

        itemizedOverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedOverlay);
    }       
}

9) Result Images

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Reference http://www.androidside.com

TabWidget

 

1) /HelloTabWidget/res/values/attr.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <declare-styleable name="Gallery1">
        <attr name="android:galleryItemBackground" />
    </declare-styleable>
</resources>

 

2) /HelloTabWidget/res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            
             <Gallery
       android:id="@+id/gallery"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
   />

            <LinearLayout
                android:id="@+id/textview2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="this is another tab">
                <TextView
     android:id="@+textview2/dateDisplay"           
     android:layout_width="wrap_content"           
     android:layout_height="wrap_content"           
     android:text=""/>   
    <Button
     android:id="@+textview2/pickDate"           
     android:layout_width="wrap_content"           
     android:layout_height="wrap_content"           
     android:text="Change the date"/>
            </LinearLayout>
           
            <TextView 
                android:id="@+id/textview3"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="this is a third tab" />
               
        </FrameLayout>
    </LinearLayout>
</TabHost>


3) /HelloTabWidget/src/my/HelloTabWidget/HelloTabWidget.java

package my.HelloTabWidget;

import java.util.Calendar;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TabActivity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class HelloTabWidget extends TabActivity  {
 TabHost mTabHost = null;
 private TextView mDateDisplay;
 private Button mPickDate;

 private int mYear;
 private int mMonth;
 private int mDay;

 static final int DATE_DIALOG_ID = 0;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        mTabHost = getTabHost();
        
        mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1", getResources().getDrawable(R.drawable.icon1)).setContent(R.id.gallery));
        mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2", getResources().getDrawable(R.drawable.icon2)).setContent(R.id.textview2));
        mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3", getResources().getDrawable(R.drawable.icon3)).setContent(R.id.textview3));
        
        mTabHost.setCurrentTab(0);
       
        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(HelloTabWidget.this, "" + (position+1), Toast.LENGTH_SHORT).show();
            }
        });
       
     // capture our View elements
        mDateDisplay = (TextView) findViewById(R.textview2.dateDisplay);
        mPickDate = (Button) findViewById(R.textview2.pickDate);

        // add a click listener to the button
        mPickDate.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                showDialog(DATE_DIALOG_ID);
            }
        });

        // get the current date
        final Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);

        // display the current date
        updateDisplay();
    }
   
    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DATE_DIALOG_ID:
            return new DatePickerDialog(this,
                        mDateSetListener,
                        mYear, mMonth, mDay);
        }
        return null;
    }
   
    private void updateDisplay() {
        mDateDisplay.setText(
            new StringBuilder()
                    // Month is 0 based so add 1
              .append(mYear).append("-")
                    .append(mMonth + 1).append("-")
                    .append(mDay).append(" "));
    }
   
    private DatePickerDialog.OnDateSetListener mDateSetListener =
        new DatePickerDialog.OnDateSetListener() {

            public void onDateSet(DatePicker view, int year,
                                  int monthOfYear, int dayOfMonth) {
                mYear = year;
                mMonth = monthOfYear;
                mDay = dayOfMonth;
                updateDisplay();
            }
        };
   
    public class ImageAdapter extends BaseAdapter {
        int mGalleryItemBackground;
        private Context mContext;

        private Integer[] mImageIds = {
                R.drawable.f1,
                R.drawable.f2,
                R.drawable.f3,
                R.drawable.f4,
                R.drawable.f5,
                R.drawable.f6
        };

        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(150, 100));
            i.setScaleType(ImageView.ScaleType.FIT_XY);
            i.setBackgroundResource(mGalleryItemBackground);

            return i;
        }
    }
}

4) Relsult Images

Form configuration components

1) /HelloFormStuff/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:padding="10dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
<ImageButton
    android:id="@+id/android_button"
    android:layout_width="100dip"
    android:layout_height="wrap_content"
    android:src="@drawable/android" />  
<EditText
    android:id="@+id/edittext"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>  
<CheckBox android:id="@+id/checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="check it out" />
<RadioGroup
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal">
 
  <RadioButton android:id="@+id/radio_red"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Red" />
 
  <RadioButton android:id="@+id/radio_blue"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Blue" />
</RadioGroup>
<ToggleButton android:id="@+id/togglebutton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
<TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip"
        android:text="Please select a planet:"
    />
<Spinner android:id="@+id/spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawingCacheQuality="high"
        android:prompt="@string/planet_prompt"
    />
</LinearLayout>

2) /HelloFormStuff/res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, HelloFormStuff!</string>
    <string name="app_name">HelloFormStuff</string>
    <string name="planet_prompt">Choose a planet</string>
</resources>

3) /HelloFormStuff/res/values/arrays.xml
<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <string-array name="planets">
        <item>Chelsea</item>
        <item>ManUtd</item>
        <item>Arsenal</item>
        <item>ManCity</item>
        <item>Tottenham</item>
        <item>Liverpool</item>
        <item>AstonVilla</item>
        <item>Everton</item>
    </string-array>
</resources>

4) /HelloFormStuff/src/my/HelloFormStuff/HelloFormStuff.java
package my.HelloFormStuff;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;
import android.view.KeyEvent;
import android.view.View.OnKeyListener;
import android.widget.EditText;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.ToggleButton;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class HelloFormStuff extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final ImageButton button = (ImageButton) findViewById(R.id.android_button);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks
                Toast.makeText(HelloFormStuff.this, "I love Liverpool", Toast.LENGTH_LONG).show();
            }
        });
        
        final EditText edittext = (EditText) findViewById(R.id.edittext);
        edittext.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                  // Perform action on key press
                  Toast.makeText(HelloFormStuff.this, edittext.getText(), Toast.LENGTH_SHORT).show();
                  return true;
                }
                return false;
            }
        });
        
        final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
        checkbox.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks
                if (checkbox.isChecked()) {
                    Toast.makeText(HelloFormStuff.this, "Selected", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(HelloFormStuff.this, "Not selected", Toast.LENGTH_SHORT).show();
                }
            }
        });
        
        final ToggleButton togglebutton = (ToggleButton) findViewById(R.id.togglebutton);
        togglebutton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks
                if (togglebutton.isChecked()) {
                    Toast.makeText(HelloFormStuff.this, "ON", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(HelloFormStuff.this, "OFF", Toast.LENGTH_SHORT).show();
                }
            }
        });
        
        Spinner s = (Spinner) findViewById(R.id.spinner);
        ArrayAdapter adapter = ArrayAdapter.createFromResource(
                this, R.array.planets, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        s.setAdapter(adapter);
        
        final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
        final RadioButton radio_blue = (RadioButton) findViewById(R.id.radio_blue);
        radio_red.setOnClickListener(j_listener);
        radio_blue.setOnClickListener(j_listener);
        
    }
    
    OnClickListener j_listener = new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            RadioButton rb = (RadioButton) v;
            Toast.makeText(HelloFormStuff.this, rb.getText(), Toast.LENGTH_SHORT).show();
        }
    };
}

5) Result Image

Reference http://www.androidside.com

Linear Layout Example

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   
android:orientation="vertical"    android:layout_width="fill_parent"   
android:layout_height="fill_parent">   
 <LinearLayout        android:orientation="horizontal"       
 android:layout_width="fill_parent"       
 android:layout_height="fill_parent"       
 android:layout_weight="1">               
  <TextView           
  android:text="red"           
  android:gravity="center_horizontal"           
  android:background="#aa0000"           
  android:layout_width="wrap_content"           
  android:layout_height="fill_parent"           
  android:layout_weight="1"/>               
  <TextView           
  android:text="green"           
  android:gravity="center_horizontal"           
  android:background="#00aa00"           
  android:layout_width="wrap_content"           
  android:layout_height="fill_parent"           
  android:layout_weight="1"/>               
  <TextView           
  android:text="blue"           
  android:gravity="center_horizontal"           
  android:background="#0000aa"           
  android:layout_width="wrap_content"           
  android:layout_height="fill_parent"           
  android:layout_weight="1"/>               
  <TextView           
  android:text="yellow"           
  android:gravity="center_horizontal"           
  android:background="#aaaa00"           
  android:layout_width="wrap_content"           
  android:layout_height="fill_parent"           
  android:layout_weight="1"/>                   
 </LinearLayout>           
 <LinearLayout       
 android:orientation="vertical"       
 android:layout_width="fill_parent"       
 android:layout_height="fill_parent"       
 android:layout_weight="1">               
  <Button           
  android:text="row one"           
  android:textSize="15pt"           
  android:layout_width="fill_parent"           
  android:layout_height="wrap_content"           
  android:layout_weight="1"/>               
  <Button           
  android:text="row two"           
  android:textSize="15pt"           
  android:layout_width="fill_parent"           
  android:layout_height="wrap_content"           
  android:layout_weight="1"/>               
  <Button           
  android:text="row three"           
  android:textSize="15pt"           
  android:layout_width="fill_parent"           
  android:layout_height="wrap_content"           
  android:layout_weight="1"/>               
  <Button           
  android:text="row four"           
  android:textSize="15pt"           
  android:layout_width="fill_parent"           
  android:layout_height="wrap_content"           
  android:layout_weight="1"/>           
 </LinearLayout>       
</LinearLayout>

 

 

Reference http://www.androidside.com

2010년 4월 11일 일요일

Android base layout 1

1) Total Project configration
2) Indicate setContentView from Main.java
package kr.mobileplace.lecture;

import android.app.Activity;
import android.os.Bundle;

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

3) Setting Layout : /MobilePlace Lecture/res/layout/myactivity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:background="#FF880000"
    />
<ImageView
android:src="@drawable/icon"
android:scaleType="center"
android:layout_width="0dp"
    android:layout_height="fill_parent"  
    android:layout_weight="2"
    android:background="#FF008800"
/>
<TextView  
    android:layout_width="0dp"
    android:layout_height="fill_parent"  
    android:layout_weight="1"
    android:background="#FF000088"
    />
</LinearLayout>

4) Result Image

Reference http://www.androidpub.com/

Android of the beginner 1

1. Environment setting
1) android-sdk_r05-windows.zip Download from http://developer.android.com/sdk/index.html

2)  Eclipse(ganymede)  >  help > softwareupdate > http://dl-ssl.google.com/android/eclipse/ > install

3) console window open in setting fold >

4) New Project > Android Project > MobilePlace Lecture

5)/MobilePlace Lecture/src/kr/mobileplace/lecture/MyActivity.java
package kr.mobileplace.lecture;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class MyActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.myactivity);
Log.d("MyTag", "Print Test Log");
}
}

6) /MobilePlace Lecture/res/layout/myactivity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Let's android"
    />
</LinearLayout>

7) /MobilePlace Lecture/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="kr.mobileplace.lecture"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Main"
                  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=".MyActivity" android:label="My Activity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
    </application>
</manifest>

8) Run > Run Configuration

9) Result : Wait over one minute, it's long time. Look for the your result, MENU click!!!

Reference http://www.androidpub.com/