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
2k
Androidアプリを作る 第7回
nonylene
0
1.4k
Androidアプリを作る 第5回
nonylene
0
1.1k
Androidアプリを作る 第4回
nonylene
0
660
Androidアプリを作る 第3回
nonylene
0
1.1k
androidアプリを作る 第1・2回
nonylene
0
930
iOS アプリ作成入門
nonylene
11
3.9k
Android・iOS アプリ作成入門 Android 編
nonylene
1
1.7k
Other Decks in Technology
See All in Technology
HashHub会社案内「なぜ今、パブリックブロックチェーンに賭けるのか」
hashhub
3
75k
【shownet.conf_】3Dアプローチで守るセキュリティ
shownet
PRO
0
360
TypeScript x Raycast x AIで変える開発者体験
nagauta
0
180
Efficient zero-copy networking using io_uring
ennael
PRO
0
330
見えづらい活動の成果の伝え方は日頃からめちゃくちゃ悩んでるけど、実際こんな取り組みをしな がら温度感を合わせにいってるよ / Conveying Hard-to-See Results
kakehashi
2
320
Tracking down sources of kernel errors with retsnoop
ennael
PRO
0
150
分析者起点の企画を成功させた連携面の工夫
lycorptech_jp
PRO
1
250
山手線一周のパフォーマンス改善
suzukahr
0
150
クレジットカードを製造する技術
yutadayo
81
45k
Low Latency Join Method for Distributed DBMS
yugabytejapan
0
160
Assisted reorganization of data structures
ennael
PRO
0
250
Webセキュリティのあるきかた
akiym
30
9.4k
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
32k
Designing for Performance
lara
604
68k
Writing Fast Ruby
sferik
626
60k
No one is an island. Learnings from fostering a developers community.
thoeni
19
2.9k
Producing Creativity
orderedlist
PRO
341
39k
Become a Pro
speakerdeck
PRO
24
4.9k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
The Art of Programming - Codeland 2020
erikaheidi
51
13k
Infographics Made Easy
chrislema
239
18k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
7
570
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.3k
Teambox: Starting and Learning
jrom
131
8.7k
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); ΩʔͱσϑΥϧτΛࢦఆ