CHAP 10. 고급 위젯. © 2012 생능출판사 All rights reserved 어댑터 뷰 어댑터 뷰 (AdapterView) 는 배열이나 파일, 데이터 베이스에 저장된 데이터를 화면에 표시할 때 유용한 뷰.

Slides:



Advertisements
Similar presentations
Layout and Control in UI The user interface (UI) is the graphical interface user can see and interact with your app comprising UI controls like textbox,
Advertisements

@2011 Mihail L. Sichitiu1 Android Introduction Hello Views Part 1.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Android Selection Widgets Các Widget cho phép chọn Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright ©
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
Presenting Lists of Data. Lists of Data Issues involved – unknown number of elements – allowing the user to scroll Data sources – most common ArrayList.
Android Application Development Tutorial. Topics Lecture 5 Overview Overview of Networking Programming Tutorial 2: Downloading from the Internet.
Wireless Mobility with Android 1 Presented by: Ung Yean MS. Computer Science American University, Washington DC, USA.
ANDROID – INTERFACE AND LAYOUT L. Grewe. Interfaces: Two Alternatives Code or XML  You have two ways you can create the interface(s) of your Application.
Package org.androidtown.database.query; import android.app.Activity; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase;
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
로봇 전화번호부 4/4 UNIT 12 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 뷰 홀더 패턴을 사용할 수 있다. 토스트를 사용할 수 있다. 클릭 이벤트를 처리할 수 있다. 2.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
Android Dialog Boxes AlertDialog - Toast
ListView.
Import import android.graphics.Bitmap; import android.widget.ImageView;
로봇 모션 편집기 4/4 UNIT 25 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 에디트 텍스트를 사용할 수 있다. 아이템을 삭제할 수 있다. 아이템을 편집할 수 있다. 2.
로봇 모니터링 1/2 UNIT 20 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Message Queue Handler 2.
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
User Interface Android Club Agenda Button OnClickListener OnLongClickListener ToggleButton Checkbox RatingBar AutoCompleteTextView.
Copyright© Jeffrey Jongko, Ateneo de Manila University Custom ListAdapters.
CHAP 11. 액티비티와 인텐트.
ListView and ExpandableListView
Android and s Ken Nguyen Clayton state University 2012.
아주대학교 LifecareScienceLAB Android Seminar 3 rd class Android Software Development 2011/05/04 – p.m. 06:00 – 팔달관 409 호 아주대학교.
Mobile Computing Lecture#12 Graphics & Animation.
CHAP 14. 프로세스와 스레드. © 2012 생능출판사 All rights reserved 다중 스레딩 하나의 애플리케이션이 동시에 여러 가지 작업을 하 는 것 이들 작업은 스레드 (thread) 라고 불린다.
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
CHAP 6. 이벤트 처리. © 2012 생능출판사 All rights reserved 폴링과 이벤트 구동 방식.
CHAP 7. 메뉴와 대화상자. © 2012 생능출판사 All rights reserved 메뉴의 종류 옵션 메뉴 : 사용자가 MENU 키를 누를 때 나타난다. 컨텍스트 메뉴 : 컨텍스트 메뉴는 사용자가 화면을 일정 시간 이상으로 길게 누르면 나타나는 메뉴이다.
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
Android 基本 I/O. 基本 I/O 介面元件 在此節中主要介紹常見的 I/O 使用者介 面元件 – Button, TextView, 以及 EditText , 學習者可以學會: – Android 的視窗表單設計 res/layout/main.xml – Android SDK –
Http :// developer. android. com / guide / topics / fundamentals. html.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Android Introduction Hello World
CS499 – Mobile Application Development
Android Layouts 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.
UNIT 11 로봇 전화번호부 3/4 로봇 SW 콘텐츠 교육원 조용수.
GUI Programming Fundamentals
Android Multi-Threading
Further android gui programming
CS499 – Mobile Application Development
Android Introduction Hello World.
Android External Resources
Android List-Based Selection Widgets
Android Widgets 1 7 August 2018
Android Introduction Hello Views Part 1.
Android – Read/Write to External Storage
Android List-Based Selection Widgets
Android Introduction Hello Views Part 2.
Android Programming Lecture 6
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
滑動 建國科技大學 資管系 饒瑞佶.
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
Adding Components to Activity
CMPE419 Mobile Application Development
BLP 4216 MOBİL UYGULAMA GELİŞTİRME-2
Lasalle-App Tecnología Móvil.
Android Sensor Programming
Android Sensor Programming
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

CHAP 10. 고급 위젯

© 2012 생능출판사 All rights reserved 어댑터 뷰 어댑터 뷰 (AdapterView) 는 배열이나 파일, 데이터 베이스에 저장된 데이터를 화면에 표시할 때 유용한 뷰

© 2012 생능출판사 All rights reserved 어댑터 뷰의 종류 리스트 뷰 (ListView), 갤러리 (Gallery), 스피너 (Spinner), 그리드 뷰 (GridView)

© 2012 생능출판사 All rights reserved 리스트 뷰 리스트 뷰 (ListView) 는 항목들을 수직으로 보여주는 어댑터 뷰로서 상하로 스크롤이 가능

© 2012 생능출판사 All rights reserved 리스트 뷰 예제 <LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:layout_width="fill_parent" android:layout_height="fill_parent" />

© 2012 생능출판사 All rights reserved 리스트 뷰 예제 public class ListViewTest extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String[] list = { " 사과 ", " 배 ", " 딸기 ", " 수박 ", " 참외 ", " 파인애플 ", " 포도 ", " 바나나 ", " 키위 ", " 귤 ", " 망고 " }; ArrayAdapter adapter; adapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, list); ListView listview = (ListView) findViewById(R.id.ListView01); listview.setAdapter(adapter); }

© 2012 생능출판사 All rights reserved 리스트 뷰와 ARRAY A DAPTER String[] list = { " 사과 ", " 배 ", " 딸기 ", " 수박 ", " 참외 ", " 파 인애플 ", " 포도 ", " 바나나 ", " 키위 ", " 귤 ", " 망고 " }; adapter = new ArrayAdapter (this,android.R.layout.simple_list_item_1, list); listview.setAdapter(adapter);

© 2012 생능출판사 All rights reserved 리스트뷰의 클릭 이벤트 처리 listview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { // 리스트 뷰의 항목이 선택되면 여기서 처리한다. } });

© 2012 생능출판사 All rights reserved 리스트 뷰 클릭 이벤트 예제 <TextView xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:textSize="20sp" android:textColor="#ff0000" > list_item.xml

© 2012 생능출판사 All rights reserved 리스트 뷰 이벤트 처리 예제... public class ListActivityTest extends ListActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] fruits = getResources().getStringArray(R.array.fruits); setListAdapter(new ArrayAdapter (this, R.layout.list_item, fruits)); ListView listview = getListView(); listview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View view, int position, long id) { Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show(); } }); }

© 2012 생능출판사 All rights reserved 리스트 뷰 이벤트 처리 예제 실행 결과

© 2012 생능출판사 All rights reserved 스피너 스피너 (Spinner) 는 항목을 선택하기 위한 드롭 다운 리스트

© 2012 생능출판사 All rights reserved 스피너 예제 <LinearLayout xmlns:android=" android:orientation="vertical" android:padding="10dip" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dip" /> <Spinner android:layout_width="fill_parent" android:layout_height="wrap_content" />

© 2012 생능출판사 All rights reserved 스피너 예제 SpinnerActivity 행성을 선택하시오 수성 금성 지구 화성 목성 토성 천왕성 해왕성 strings.xml

© 2012 생능출판사 All rights reserved 스피너 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Spinner spinner = (Spinner) findViewById(R.id.spinner); ArrayAdapter adapter = ArrayAdapter.createFromResource( this, R.array.planets_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdow n_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView parent, View view, int pos, long id) { Toast.makeText(parent.getContext(), " 선택된 행성은 " + parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show(); } public void onNothingSelected(AdapterView arg0) { } }); }

© 2012 생능출판사 All rights reserved 실행 결과

© 2012 생능출판사 All rights reserved 그리드 뷰 2 차원의 그리드에 항목들을 표시하는 뷰그룹

© 2012 생능출판사 All rights reserved 그리드 뷰 예제 <GridView xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:columnWidth="90dp" android:numColumns="auto_fit" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:stretchMode="columnWidth" android:gravity="center" />

© 2012 생능출판사 All rights reserved 그리드 뷰 예제 public class GridViewTest extends Activity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); GridView gridview = (GridView) findViewById(R.id.GridView01); gridview.setAdapter(new ImageAdapter(this)); gridview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { Toast.makeText(GridViewTest.this, "" + position, Toast.LENGTH_SHORT).show(); } }); }

© 2012 생능출판사 All rights reserved 실행결과

© 2012 생능출판사 All rights reserved 갤러리 항목들이 수평으로 스크롤되면서 중심에 놓인 현재 항목을 강조해서 보여주는 위젯

© 2012 생능출판사 All rights reserved 레이아웃 파일 <Gallery xmlns:android=" android:layout_width="fill_parent" android:layout_height="wrap_content" />

© 2012 생능출판사 All rights reserved 코드... public class GalleryTest extends Activity 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(GalleryTest.this, "" + position, Toast.LENGTH_SHORT).show();} }); }

© 2012 생능출판사 All rights reserved I MAGE A DAPTER 클래스... public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; private Context mContext; private Integer[] mImageIds = { R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3, R.drawable.sample_4, R.drawable.sample_5,R.drawable.sample_6, R.drawable.sample_7 }; public ImageAdapter(Context c) { mContext = c; } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; }

© 2012 생능출판사 All rights reserved I MAGE A DAPTER 클래스 public long getItemId(int position) { return position; } public View getView(intposition, 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; }

© 2012 생능출판사 All rights reserved 실행결과

© 2012 생능출판사 All rights reserved 프로그레스 바 작업의 진행 정도를 표시하는 위젯

© 2012 생능출판사 All rights reserved 레이아웃 파일 <LinearLayout xmlns:android= android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ProgressBar android:layout_width="fill_parent" android:layout_height="wrap_content" >

© 2012 생능출판사 All rights reserved 코드... public class ProgressBarTest extends Activity { private static final int PROGRESS = 0x1; private ProgressBar mProgress private int mProgressStatus = 0; private Handler mHandler = new protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main);

© 2012 생능출판사 All rights reserved 코드 mProgress = (ProgressBar) findViewById(R.id.ProgressBar01); // 백그라운드 스레드 new Thread(new Runnable() public void run() { while (true) { if (mProgressStatus < 100) mProgressStatus += 10; else mProgressStatus = 0; mHandler.post(new Runnable() public void run() { mProgress.setProgress(mProgressStatus); } }); try { Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } }).start(); }

© 2012 생능출판사 All rights reserved 실행 결과

© 2012 생능출판사 All rights reserved 레이팅 바 레이팅 바는 별을 사용하여서 점수를 표시하는 위젯

© 2012 생능출판사 All rights reserved 레이아웃 파일 <LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <RatingBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:numStars="5" android:stepSize="1.0" />

© 2012 생능출판사 All rights reserved 코드 public class RatingBarTest extends Activity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final RatingBar ratingbar = (RatingBar) findViewById(R.id.ratingbar); ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() { public void onRatingChanged(RatingBar ratingBar, float rating,boolean fromUser) { Toast.makeText(RatingBarTest.this, " 점수 : "+ rating, Toast.LENGTH_SHORT).show();} }); }

© 2012 생능출판사 All rights reserved 실행 결과

© 2012 생능출판사 All rights reserved 데이터 픽커와 타임 픽커

© 2012 생능출판사 All rights reserved 레이아웃 파일 <LinearLayout xmlns:android=" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=""/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" 날짜변경 />

© 2012 생능출판사 All rights reserved 코드 private TextView mDateDisplay; private Button mPickDate; private int mYear; private int mMonth; private int mDay; static final int DATE_DIALOG_ID = 0;

© 2012 생능출판사 All rights reserved 코드 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mDateDisplay = (TextView) findViewById(R.id.dateDisplay); mPickDate = (Button) findViewById(R.id.pickDate); mPickDate.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showDialog(DATE_DIALOG_ID); } }); final Calendar c = Calendar.getInstance(); mYear = c.get(Calendar.YEAR); mMonth = c.get(Calendar.MONTH); mDay = c.get(Calendar.DAY_OF_MONTH); updateDisplay(); }

© 2012 생능출판사 All rights reserved 코드 private void updateDisplay() { mDateDisplay.setText(new StringBuilder() // 월은 0 부터 시작한다. 따라서 1 을 더한다..append(mMonth + 1).append("-").append(mDay).append("-").append(mYear).append(" ")); }

© 2012 생능출판사 All rights reserved 코드 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(); }

© 2012 생능출판사 All rights reserved protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID: return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay); } return null; }

© 2012 생능출판사 All rights reserved 실행 결과