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
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.6k
Androidのログ出力をいい感じにする #potatotips 9
cutmail
8
10k
コーディング規約を緩く守りつつ仕事の成果を出す方法
cutmail
2
670
Other Decks in Programming
See All in Programming
From 6 People Classroom Meetup to 100 People Regional Conference / FOSS4G Hiroshima 2026
furukawayasuto
0
210
iOSDC2026登壇資料.pdf
riofujimon
0
170
Intent as Code
shoppingjaws
6
1k
SONY CISC-NEWS NWS-1750 + NWB-225 フレームバッファの NetBSD/news68k ドライバ実装 / OSC2026Hiroshima
tsutsui
0
110
『寄り添うラジオ』をAIで作る 体験価値から逆算した、会話しないUXと品質設計
theoriatec2024
3
180
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
1
330
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
3k
kubernetes コンポーネント開発入門 / 新卒N年目の勉強会&交流会!〜〇〇への誘い〜 #n_study
mazrean
0
240
setup-vp GitLab対応の裏側
naokihaba
0
100
Building an Out-of-Order CPU
latte72
1
780
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
340
AIエージェント時代のコードレビューを設計する
nogu66
6
2.7k
Featured
See All Featured
The browser strikes back
jonoalderson
0
1.7k
Believing is Seeing
oripsolob
1
220
Mind Mapping
helmedeiros
1
360
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
350
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
440
What does AI have to do with Human Rights?
axbom
PRO
1
2.4k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
300
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
510
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
540
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
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ͷංେԽ͕ ͛Δ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ