Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Adapter and Custom Layout
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Tatsuya Arai
February 18, 2015
Programming
990
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Adapter and Custom Layout
Tatsuya Arai
February 18, 2015
More Decks by Tatsuya Arai
See All by Tatsuya Arai
5 minutes PWA
cutmail
0
250
Androidアプリ開発における技術顧問としての役割 #DroidKaigi 2018
cutmail
1
2.5k
4年続くアプリにおけるチーム開発 #DroidKaigi 2017
cutmail
13
5k
フリルにおけるドッグフーディング / Fashion Tech Meetup #2 LT
cutmail
2
4k
いかにして不具合発見時の フィードバックを素早く行うか #potatotips 12
cutmail
0
2.7k
Androidのログ出力をいい感じにする #potatotips 9
cutmail
8
10k
コーディング規約を緩く守りつつ仕事の成果を出す方法
cutmail
2
680
Other Decks in Programming
See All in Programming
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
34
15k
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
190
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
350
すこし踏み込む CancellationToken
htkym
2
1.6k
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
630
カツオ、ご期待ください
suneo3476
0
150
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
20
21k
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
140
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
480
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.8k
JRuby: Past, Present, and Future
headius
0
220
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
160
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
5.2k
Building AI with AI
inesmontani
PRO
1
1.3k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
The SEO Collaboration Effect
kristinabergwall1
1
590
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
740
Accessibility Awareness
sabderemane
1
240
Optimizing for Happiness
mojombo
378
71k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
350
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
370
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
The agentic SEO stack - context over prompts
schlessera
0
970
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
460
Transcript
"EBQUFSBOE $VTUPN-BZPVU QPUBUPUJQT
@cutmail • Fablic, Inc. • Co-Founder • Mobile Application Engineer
AdapterͷߴԽ
AdapterͷߴԽ • ViewHolder
ViewHolder • AdapterͷߴԽख๏ • Adapter#getView()ͰfindViewById()ͷճΛݮΒ͢ (ViewΛ͍·Θ͢)
public class ItemAdapter extends ArrayAdapter<Item> { private LayoutInflater inflater; private
List<Item> items; @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder viewHolder; if (convertView == null) { convertView = inflater.inflate(R.layout.list_item, parent, false); viewHolder = new ViewHolder(); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } Item item = getItem(position); viewHolder.titleView.setText(item.getItemName()); return convertView; } public static class ViewHolder { ImageView thumbnail; TextView titleView; public ViewHolder(View view) { this.thumbnail = (ImageView) view.findViewById(R.id.thumbnail); this.titleView = (TextView) view.findViewById(R.id.title); } } } 7JFXͷࢀরΛอ࣋ ॳճͷΈ7JFX)PMEFSΛੜ
ෳͷҟͳΔϨΠΞτ 5JUMF 5JUMF 5JUMF 5JUMF %BUF %BUF %BUF
ViewType @Override public int getViewTypeCount() { return 2; } @Override
public int getItemViewType(int position) { if (position % 1 == 0) { return VIEW_TYPE_ODD; } else { return VIEW_TYPE_EVEN; } } ϨΠΞτͷछྨ QPTJUJPOʹରͯ͠ͲͷϨΠΞτΛ͏͔
ෳϨΠΞτ(ViewHolder) public static class ViewHolderOdd { TextView title; ImageView image;
} public static class ViewHolderEven { TextView title; TextView detail; ImageView image; }
ෳϨΠΞτ(ViewHolder൛) @Override public View getView(int position, View convertView, ViewGroup parent)
{ ViewHolder1 viewHolder1; ViewHolder2 viewHolder2; Item item = getItem(position); switch (getItemViewType(position)) { case VIEW_TYPE_ODD: if (convertView == null) { convertView = inflater.inflate(R.layout.list_item_1, parent, false); viewHolder1 = new ViewHolder(convertView); convertView.setTag(viewHolder1); } else { viewHolder1 = 1(ViewHolder) convertView.getTag(); } holder.title.setText(item.getName()); Picasso.with(getContext()) .load(item.getImageUrl) .placeholder(R.drawable.icon_user) .error(R.drawable.icon_user) .resizeDimen(R.dimen.list_item_user_icon_size, R.dimen.list_item_user_icon_size) .centerCrop() .into(holder.imageView); break; case VIEW_TYPE_EVEN: ɾɾɾ ɾɾɾ return convertView; } ͍
AdapterͷංେԽ • ViewHolderAdapter͕ංେ͍͢͠ • ෳϨΠΞτରԠ͢Δͱ͞ΒʹංେԽ • AdapterͷׂViewͱදࣔσʔλͷbinding • Viewͷදࣔॲཧ֤ViewΫϥε͕ॲཧ͢Δ͖
AdapterͷߴԽ • ViewHolder • Custom Layout
Custom Layoutͷಋೖ
LayoutΛܧঝͯ͠Custom LayoutΛ࡞ public class NormalLayout extends LinearLayout { TextView titleView;
ImageView imageView; @Override protected void onFinishInflate() { super.onFinishInflate(); titleView = (TextView) findViewById(R.id.title); imageView = (ImageView) findViewById(R.id.image); } public void setItem(Item item) { titleView.setText(item.getItemName()); Picasso.with(getContext()) .load(item.getImageUrl) .placeholder(R.drawable.icon_user) .error(R.drawable.icon_user) .resizeDimen(R.dimen.icon_size, R.dimen.user_icon_size) .centerCrop() .into(holder.imageView); } } PO'JOJTI*OqBUF ͕ݺΕͨޙʹpOE7JFX#Z*E ͢Δ͜ͱͰ 7JFX)PMEFSͱಉ༷ͷޮՌ͕ಘΒΕΔ
@Override public View getView(int position, View convertView, ViewGroup parent) {
NormalLayout normalLayout; SpecialLayout specialLayout; Item item = getItem(position); switch (getItemViewType(position)) { case VIEW_TYPE_ODD: if (convertView != null && (convertView instanceof NormalLayout)) { normalLayout = (NormalLayout) convertView; } else { normalLayout = (NormalLayout) inflater.inflate(R.layout.list_item_odd, parent, false); } normalLayout.setItem(item); return normalLayout; case VIEW_TYPE_EVEN: ɾɾɾ return specialLayout; } return null; } ෳϨΠΞτ(Custom Layout൛) -BZPVUपΓͷίʔυ͕ݮ͖ͬͯͬ͢Γ
ෳϨΠΞτ(ViewHolder൛) @Override public View getView(int position, View convertView, ViewGroup parent)
{ ViewHolder1 viewHolder1; ViewHolder2 viewHolder2; Item item = getItem(position); switch (getItemViewType(position)) { case VIEW_TYPE_ODD: if (convertView == null) { convertView = inflater.inflate(R.layout.list_item_1, parent, false); viewHolder1 = new ViewHolder(convertView); convertView.setTag(viewHolder1); } else { viewHolder1 = 1(ViewHolder) convertView.getTag(); } holder.title.setText(item.getName()); Picasso.with(getContext()) .load(item.getImageUrl) .placeholder(R.drawable.icon_user) .error(R.drawable.icon_user) .resizeDimen(R.dimen.list_item_user_icon_size, R.dimen.list_item_user_icon_size) .centerCrop() .into(holder.imageView); break; case VIEW_TYPE_EVEN: ɾɾɾ ɾɾɾ return convertView; }
ϦετͷදࣔཁૉΛमਖ਼Λ͢Δࡍ AdapterͰͳ͘ɺ Custom LayoutΫϥεΛमਖ਼͢ΕOK
ଞͷAdapterͰCustom Layout Λ͏͜ͱՄೳ
(SJE7JFXಉ༷ʹରԠՄೳ
·ͱΊ • Custom LayoutΛ͏͜ͱͰAdapterͷංେԽ͕ ͛Δ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ