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.2k
Androidアプリを作る 第4回
nonylene
0
700
Androidアプリを作る 第3回
nonylene
0
1.2k
androidアプリを作る 第1・2回
nonylene
0
980
iOS アプリ作成入門
nonylene
11
3.9k
Android・iOS アプリ作成入門 Android 編
nonylene
1
1.7k
Other Decks in Technology
See All in Technology
embedパッケージを深掘りする / Deep Dive into embed Package in Go
task4233
1
210
深層学習と3Dキャプチャ・3Dモデル生成(土木学会応用力学委員会 応用数理・AIセミナー)
pfn
PRO
0
460
Evolving Architecture
rainerhahnekamp
3
250
AWS re:Invent 2024 recap in 20min / JAWSUG 千葉 2025.1.14
shimy
1
100
#TRG24 / David Cuartielles / Post Open Source
tarugoconf
0
580
技術に触れたり、顔を出そう
maruto
1
150
「隙間家具OSS」に至る道/Fujiwara Tech Conference 2025
fujiwara3
7
6.5k
新卒1年目、はじめてのアプリケーションサーバー【IBM WebSphere Liberty】
ktgrryt
0
120
I could be Wrong!! - Learning from Agile Experts
kawaguti
PRO
8
3.4k
re:Invent2024 KeynoteのAmazon Q Developer考察
yusukeshimizu
1
150
Docker Desktop で Docker を始めよう
zembutsu
PRO
0
170
RubyでKubernetesプログラミング
sat
PRO
4
160
Featured
See All Featured
Faster Mobile Websites
deanohume
305
30k
Building an army of robots
kneath
302
45k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
The Language of Interfaces
destraynor
155
24k
The World Runs on Bad Software
bkeepers
PRO
66
11k
GraphQLとの向き合い方2022年版
quramy
44
13k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
The Cost Of JavaScript in 2023
addyosmani
46
7.2k
Unsuck your backbone
ammeep
669
57k
A Philosophy of Restraint
colly
203
16k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7.1k
Building Your Own Lightsaber
phodgson
104
6.2k
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); ΩʔͱσϑΥϧτΛࢦఆ