'Interesting/ANDROID'에 해당되는 글 50

  1. 2007.12.13 연습1 : 노트패드
  2. 2007.11.20 [ANDROID] Hello, Android 프로젝트 만들기
  3. 2007.11.14 [안드로이드학? : 2-3] Androidology - Part 2 and 3
Interesting/ANDROID | Posted by hyena0 2007. 12. 13. 00:37

연습1 : 노트패드

Notepad Exercise 1
 안드로이드 홈피에 나오는 노트패드 연습을 정리합니다.
 
 Step 1
 이클립스에서 Notepadv1를 연다.
 이클립스의 패키지 익스플로러에서 마우스의 오른쪽 클릭을 하고 Import를 선택한다.
 여기서 General/Existing Projects into Workspace를 선택한다.
 Notepadv1의 폴더를 선택하고 finish 버튼을 누른다.
 이클립스 우측하단에 에러표시가 나면, 프로젝트를 선택하고 마우스 오른쪽 키를 누르면 Android Tools->Fix Project Properties 가 있는데 이것을 선택하면 해결된다고 홈피에는 나와있다.
 내가해본 결과로는 Fix 하더라도 문제가 여전히 남고 우측하단에 나온 에러를 더블클릭해서 문제점을 찾는 것이 더 빠른 길인 걸로 보인다.

 Step 2
 DBHelper 를 보라...음...

 Step 3, Step 4
 프로젝트를 선택하고 res/layout 에서 notepad_list.xml를 연다. 아래의 파란부분의 코드를 추가한다.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
 // 추가코드
  <ListView id="@id/android:list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
  <TextView id="@id/android:empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/no_notes"/>
//여기까지
</LinearLayout>
 
 Step 5
프로젝트를 선택하고 res/layout 에서 notepad_row.xml를 생성한다. 아래의 코드를 추가한다.

<?xml version="1.0" encoding="utf-8"?>
<TextView id="@+id/text1"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>


 Step 6
 Source 부분에서 Notepadv1 Class를 연다.

 Step 7
 Notepadv1 의 상속성을 Activity 에서 ListActivity 로 바꾼다.

public class Notepadv1 extends ListActivity

 ListActivity로 변경하고 나면 에러가 발생하는데 ctrl-shift-O를 눌러서 import 시킨다.

 Step 8
 Notepadv1 클래스에는 이미 onCreate, onCreateOptionsMenu, onOptionsItemSelected 메소드가 존재하고 있다.

 Step 9
 아래와 같이 변경한다.

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        setContentView(R.layout.notepad_list);
        dbHelper = new DBHelper(this);
        fillData();

    }

 Step 10
 onCreateOptionsMenu() 메소드는 아래와 같이 바꾼다.

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // TODO Auto-generated method stub
        //return super.onCreateOptionsMenu(menu);
     boolean result = super.onCreateOptionsMenu(menu);
        menu.add(0, INSERT_ID, R.string.menu_insert);
        return result;

    }

그리고 에러가 발생하게 되는데, 상수를 정의한다.

public static final int INSERT_ID = Menu.FIRST;

 Step 11
 onOptionsItemSelected()를 채운다.

@Override
    public boolean onOptionsItemSelected(Item item) {
        switch (item.getId()) {
        case INSERT_ID:
            createNote();
            break;
        }
      
        return super.onOptionsItemSelected(item);
    }

 Step 12
 createNote()를 추가한다.

private void createNote() {
        String noteName = "Note " + noteNumber++;
        dbHelper.createRow(noteName, "");
        fillData();
    }


 Step 13
 fillData()를 정의하지 않았으므로 여전히 에러를 표시하고 있을 것이다.

    private void fillData() {
        // We need a list of strings for the list items
        List<String> items = new ArrayList<String>();

        // Get all of the rows from the database and create the item list
        List<Row> rows = dbHelper.fetchAllRows();
        for (Row row : rows) {
            items.add(row.title);
        }
       
        // Now create an array adapter and set it to display using our row
        ArrayAdapter<String> notes =
            new ArrayAdapter<String>(this, R.layout.notes_row, items);
        setListAdapter(notes);
       
    }

 Step 14
  프로젝트를 선택하고 마우스 오른쪽 클릭한 뒤 Run As -> Android Application 하여 실행해보자

 아래 처럼 메뉴를 볼 수 있을 것이다.

사용자 삽입 이미지

Hello Android 프로젝트 만들기

프로젝트는 이클립스 플러그인을 이용하면 쉽게 만들 수 있다. 이클립스는 Eclipse 3.2 이나 3.3 이 설치되어 있어야 하고 Android Plugin for Eclipse 를 설치하는 것이 필요하다.

우선 "Hello, World!"는 아래와 같은 절차를 거치면 된다.

  1. 새 프로젝트 Android Project 를 생성한다.

    이클립스에서 다음 메뉴를 선택한다. File > New > Project .안드로이드 플러그인이 설치되어 있다면 아래 그림과 같은 "Android" 메뉴가 나타나는데 이것을 선택하면 "Android Project"가 나타날 것이다..

    Once you've selected "Android Project", press the Next button.

  2. 프로젝트 세부항목을 채워넣는다. 예는 다음과 같다 :

  3. 자동생성된 소스코드를 수정하면 된다. HelloAndroid 클래스는 다음과 같이 생겼다. :
    public class HelloAndroid extends Activity
    {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle icicle)
        {
            super.onCreate(icicle);
            setContentView(R.layout.main);
        }
    }

Androidology - Part 2

Application lifecycle



Androidology - Part 3

APIs

location manager
: 위치를 등록시켜 일어나는 상황에 따라 가까운 곳의 위치를 알려줌

XMPP Service
: 디바이스에서 디바이스로 다른 안드로이드 사용자에게 메시지를 보내도록 허용하는 것이다.
Gmail account 가 있으면 작동하고 서버에서 디바이스로 메시지를 전달하는 기능도 한다.

notification manager
: 메시지를 창에다가 알려주는 기능이다.
 알림기능은 연관된 동작(버튼, ...)을 가질 수 있다.

Views
: 다양한 멀티 기능(키보드, 버튼,...)의 뷰를 보여줄 수 있도록 되어 있다.