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
680
Androidアプリを作る 第3回
nonylene
0
1.2k
androidアプリを作る 第1・2回
nonylene
0
950
iOS アプリ作成入門
nonylene
11
3.9k
Android・iOS アプリ作成入門 Android 編
nonylene
1
1.7k
Other Decks in Technology
See All in Technology
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
AWS Lambdaと歩んだ“サーバーレス”と今後 #lambda_10years
yoshidashingo
1
170
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
370
Terraform CI/CD パイプラインにおける AWS CodeCommit の代替手段
hiyanger
1
240
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
3
180
適材適所の技術選定 〜GraphQL・REST API・tRPC〜 / Optimal Technology Selection
kakehashi
1
150
スクラム成熟度セルフチェックツールを作って得た学びとその活用法
coincheck_recruit
1
140
[FOSS4G 2019 Niigata] AIによる効率的危険斜面抽出システムの開発について
nssv
0
310
Why does continuous profiling matter to developers? #appdevelopercon
salaboy
0
180
ドメイン名の終活について - JPAAWG 7th -
mikit
33
20k
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
220
第1回 国土交通省 データコンペ参加者向け勉強会③- Snowflake x estie編 -
estie
0
120
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Navigating Team Friction
lara
183
14k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
It's Worth the Effort
3n
183
27k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
Done Done
chrislema
181
16k
GraphQLとの向き合い方2022年版
quramy
43
13k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
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); ΩʔͱσϑΥϧτΛࢦఆ