Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Androidアプリを作る 第6回
Search
nonylene
December 26, 2016
Technology
1
1.1k
Androidアプリを作る 第6回
nonylene
December 26, 2016
Tweet
Share
More Decks by nonylene
See All by nonylene
Elasticsearch で部内 Wiki 検索高速化
nonylene
1
2.1k
Androidアプリを作る 第7回
nonylene
0
1.4k
Androidアプリを作る 第5回
nonylene
0
1.1k
Androidアプリを作る 第4回
nonylene
0
690
Androidアプリを作る 第3回
nonylene
0
1.2k
androidアプリを作る 第1・2回
nonylene
0
970
iOS アプリ作成入門
nonylene
11
3.9k
Android・iOS アプリ作成入門 Android 編
nonylene
1
1.7k
Other Decks in Technology
See All in Technology
どちらを使う?GitHub or Azure DevOps Ver. 24H2
kkamegawa
0
620
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
1
110
継続的にアウトカムを生み出し ビジネスにつなげる、 戦略と運営に対するタイミーのQUEST(探求)
zigorou
0
500
祝!Iceberg祭開幕!re:Invent 2024データレイク関連アップデート10分総ざらい
kniino
2
240
オプトインカメラ:UWB測位を応用したオプトイン型のカメラ計測
matthewlujp
0
170
MLOps の現場から
asei
6
630
AWS re:Invent 2024 ふりかえり
kongmingstrap
0
130
DevOps視点でAWS re:invent2024の新サービス・アプデを振り返ってみた
oshanqq
0
180
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
180
AWS re:Invent 2024で発表された コードを書く開発者向け機能について
maruto
0
180
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
420
Amazon SageMaker Unified Studio(Preview)、Lakehouse と Amazon S3 Tables
ishikawa_satoru
0
150
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1366
200k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Embracing the Ebb and Flow
colly
84
4.5k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Become a Pro
speakerdeck
PRO
26
5k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Unsuck your backbone
ammeep
669
57k
RailsConf 2023
tenderlove
29
940
Fireside Chat
paigeccino
34
3.1k
Designing for humans not robots
tammielis
250
25k
Making the Leap to Tech Lead
cromwellryan
133
9k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Transcript
"OESPJEΞϓϦΛ࡞Δ ,.$OPOZMFOF ը૾ؔɾ+BWB͔ΒͷϨΠΞτɾઃఆ
ࣗݾհ w OPOZMFOF ͷʹΕΜ w ,.$ճ w ΧʔϏΟͰ͢ w
ϙέϞϯϐΫϩεপ w SPPU
ࣗݾհ w OPOZMFOF ͷʹΕΜ w εϚϗΞϓϦͱ͔ w 5XJUUFS(JU)VCFUD w
IUUQOPOZMFOFIBUFOBCMPHKQ
͜ΜΜ
ࠓΔ͜ͱ ը૾ؔ *NBHF7JFX ϨΠΞτGSPN+BWB ઃఆอଘ
ը૾ؔ
*NBHF7JFX w Drawable Λදࣔ͢ΔͨΊͷView ௨ৗͷ View ͷ background ͰදࣔͰ͖Δ͕ɺେ͖͞มߋͳͲ͕Ͱ͖ͳ͍.
"OESPJEͷը૾ͷදݱ • Bitmap w ը૾Λද͢ • Drawable w ʮը໘ʹදࣔ͞ΕΔͷʯΛද͢ w
ը૾͔͠Εͳ͍͠ɺͨͩͷ৭͔͠Εͳ͍ w ImageViewഎܠͰදࣔ͞ΕΔͷ͜Ε
"OESPJEͷը૾ͷදݱ "OJNBUJPO %SBXBCMF #JUNBQ $PMPS "OJNBUJPO #JUNBQ%SBXBCMF $PMPS%SBXBCMF %SBXBCMF $POWFSU
ը૾Λஔ • res/drawable/ ʹ Drawable Λઃஔ͢Δ w ࠓճը૾ 1/('JMF
w 9.-Ͱهड़͢Δ͜ͱՄೳ w ϑΝΠϧΛίϐʔ͢ΔPS "OESPJE4UVEJPܦ༝Ͱίϐʔ͢Δ ղ૾ผʹ࠷దͳը૾Λ༻ҙ͢Δ͜ͱͰ͖Δ (drawable-hdpi ͳͲ)
ஔྫ
ը૾Λදࣔ • android:src • ImageView Ͱදࣔ͢Δ Drawable Λઃఆ <ImageView android:layout_width="100dp"
android:layout_height="100dp" android:src="@drawable/kirby" />
ը૾Λදࣔ
ը૾Λදࣔ w ิ w android:scaleTypeͰը૾ͷ֦େํ๏ΛબΔ w ৄࡉলུ
-BZPVU GSPN+BWB
+BWBͰͷϨΠΞτ w 9.-ʹॻ͍͍֤ͯͨView+BWBͷΫϥε • TextView -> android.widget.TextView • EditText ->
android.widget.EditText • શͯ View ΫϥεͷࢠΫϥε XML Ͱ android.widget ʹ͋Δ View ಛผʹύοέʔδ໊ΛলུͰ͖͍ͯͨ. ಠࣗͷ View ͷ߹লུͰ͖ͳ͍.
7JFXͷຊ࣭+BWB w 7JFXͷॳظԽ7JFXͷίϯετϥΫλͰ։࠵ 9.-Λύʔεʢղੳʣ 7JFXͷॳظԽॲཧΛ࣮ߦ ɾ ྫandorid:text#setText(…)
7JFXΛऔಘ
7JFXΛऔಘ • View #findViewById(int id) w ActivityViewGroupʹੜ͑ͯΔ w ࢦఆͨ͠idͷViewΛऔಘ
7JFXΛऔಘ * MainActivity.java // setContentView લʹߦ͏ͱ View ͕औಘͰ͖ͳ͍ setContentView(R.layout.activity_main); EditText
editText = (EditText) findViewById(R.id.post_edit); Button submitButton = (Button) findViewById(R.id.post_button);
* MainActivity.java // setContentView લʹߦ͏ͱ View ͕औಘͰ͖ͳ͍ setContentView(R.layout.activity_main); EditText editText
= (EditText) findViewById(R.id.post_edit); Button submitButton = (Button) findViewById(R.id.post_button); 7JFXΛऔಘ *%͕FEJU@UFYUͷ7JFXΛऔಘ
* MainActivity.java // setContentView લʹߦ͏ͱ View ͕औಘͰ͖ͳ͍ setContentView(R.layout.activity_main); EditText editText
= (EditText) findViewById(R.id.post_edit); Button submitButton = (Button) findViewById(R.id.post_button); 7JFXΛऔಘ &EJU5FYUʹΩϟετͯ͠ೖ findViewById ͷฦΓ View ݻఆͳͷͰΩϟετ͢Δඞཁ͕͋Δ
7JFXΛ +BWB͔Βૢ࡞
7JFXΛૢ࡞ w 7JFXͷؔΛݺͿ͜ͱͰૢ࡞͕Մೳ editText.setHint(“KMC"); editText.setVisibility(View.GONE); imageView.setImageResource(R.drawable.kirby); // pixel ୯ҐͳͷͰҙ submitButton.setWidth(300);
// ॻ͔Εͨจࣈྻ͕ฦͬͯ͘Δ editText.getText();
w ͓͢͢Ί͠·ͤΜ w දࣔ͢Δ͚ͩͷίʔυ͕͘ෳࡶʹͳΔ w ࣮ࡍͬͯΔਓ͍Δ͚Ͳʜ w දࣔͷઃఆͱڍಈͷઃఆ͚͍ͨ w 9.-ʹॻ͚Δ෦ॻ͘͜ͱ͕ଟ͍
શ෦+BWBͰॻ͚ศརʁ
ΫϦοΫ࣌ͷڍಈ
ΫϦοΫ࣌ͷڍಈ • View#setOnClickListener( OnClickListener listener) • ΫϦοΫ͞Εͨ࣌ʹݺΕΔϦεφΛઃఆ͢Δ • View.OnClickListener Λઃఆ
• View.OnCliclListener ͱʁ
7JFX0O$MJDL-JTUFOFS w ϝιου͕Ұͭઃఆ͞ΕͨΠϯλʔϑΣʔε w ΫϦοΫ࣌ʹonClick͕ݺͼग़͞ΕΔ * View.java (Android SDK) public
interface OnClickListener { void onClick(View v); }
ΫϦοΫͰτʔετ
* MainActivity.java submitButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View
v) { Toast.makeText(v.getContext(), “clicked!”, Toast.LENGTH_LONG ).show(); } } ); ϘλϯΫϦοΫͰτʔετɹ
* MainActivity.java submitButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View
v) { Toast.makeText(v.getContext(), “clicked!”, Toast.LENGTH_LONG ).show(); } } ); ϘλϯΫϦοΫͰτʔετɹ 0O$MJDL-JTUFOFSͷແ໊ΦϒδΣΫτ
* MainActivity.java submitButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View
v) { Toast.makeText(v.getContext(), “clicked!”, Toast.LENGTH_LONG ).show(); } } ); ϘλϯΫϦοΫͰτʔετɹ ΫϦοΫ͢ΔͱݺΕΔؔ
* MainActivity.java submitButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View
v) { Toast.makeText(v.getContext(), “clicked!”, Toast.LENGTH_LONG ).show(); } } ); ϘλϯΫϦοΫͰτʔετɹ τʔετΛදࣔ
ϘλϯΫϦοΫͰτʔετɹ ˠ Click
ઃఆอଘ
ઃఆอଘ w ͍͔ͭ͘ͷํ๏͕͋Δ w 4IBSFE1SFGFSFODF w ࠓճΓ·͢ w 4RMJUF σʔλϕʔε
w ֎෦ϥΠϒϥϦ
4IBSFE1SFGFSFODF w ઃఆͳͲΛอଘ͢ΔΈ w ΩʔόϦϡʔܗࣜͰอଘ w த9.- w อଘͰ͖ΔܕݶΒΕ͍ͯΔ •
int, long, float, boolean, String, Set<String>
4IBSFE1SFGFSFODF w ෳͷ9.-ϑΝΠϧʹอଘͰ͖Δ w ϑΝΠϧ͝ͱʹΩʔ໊Ұҙ w ࠓճσϑΥϧτͷ9.-ϑΝΠϧΛ༻ w ϑΝΠϧΛؒҧ͑ͯϋϚΒͳ͍Α͏ʹ w
ؒҧ͑ͯެ։͞ΕΔ͜ͱ͕ͳ͍Α͏ʹ w ઃఆʹΑͬͯଞͷΞϓϦͰಡΈऔΕͯ͠·͏
4IBSFE1SFGFSFODF • σϑΥϧτͷ SharedPreferences Λऔಘ • ϑΝΠϧ͝ͱͷઃఆ (SharedPreference) Λཧ͢ΔΫϥε
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Static ϝιου
4IBSFE1SFGFSFODFT w อଘ sharedPreferences.edit() .putInt("hoge", 1) .putString("piyo", "piyoipyo") .putBoolean("foo", true)
.apply();
4IBSFE1SFGFSFODFT w อଘ sharedPreferences.edit() .putInt("hoge", 1) .putString("piyo", "piyoipyo") .putBoolean("foo", true)
.apply(); 4IBSFE1SFGFSFOFT&EJUPSΛऔಘ
w อଘ sharedPreferences.edit() .putInt("hoge", 1) .putString("piyo", "piyoipyo") .putBoolean("foo", true) .apply();
4IBSFE1SFGFSFODFT ΩʔͱΛ֨ೲ put~~~ ͷฦΓ editor ࣗͳͷͰ͜ͷΑ͏ʹॻ͚Δ ʢνΣʔϯϝιουͱ͍͏ʣ.
w อଘ sharedPreferences.edit() .putInt("hoge", 1) .putString("piyo", "piyoipyo") .putBoolean("foo", true) .apply();
4IBSFE1SFGFSFODFT ઃఆΛө commit() ಉظతͰ͕͔͔࣌ؒΔͷͰඇਪ
4IBSFE1SFGFSFODFT w औΓग़͠ sharedPreferences.getInt("hoge", 0); sharedPreferences.getString("piyo", null); sharedPreferences.getBoolean("foo", false); ΩʔͱσϑΥϧτΛࢦఆ