SlideShare ist ein Scribd-Unternehmen logo
1 von 10
‫ید‬‫و‬‫اندر‬ ‫در‬‫ی‬ ‫ش‬‫ر‬‫سفا‬‫لیست‬ ‫یک‬‫ایجاد‬‫ش‬‫ز‬‫آمو‬
Parmistech.com
Ehsan Ghorbannezhad
Android Programming - 2014
list_row_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/list_row_bg" android:state_pressed="false"
android:state_selected="false"/>
<item android:drawable="@drawable/list_row_bg_hover" android:state_pressed="true"/>
<item android:drawable="@drawable/list_row_bg_hover" android:state_pressed="false"
android:state_selected="true"/>
</selector>
‫فایل‬‫یک‬ ‫بر‬‫ی‬‫مرور‬selector‫انتخاب‬ ‫هنگام‬ ‫در‬‫لیست‬‫های‬‫آیتم‬ ‫کردت‬ ‫هایالیت‬‫ای‬‫ر‬‫ب‬
Parmistech.com
 <RelativeLayout >
 <ImageView android:id="@+id/thumbnail" />
 <TextView android:id="@+id/title" />
 <TextView android:id="@+id/rating"/>
 <TextView android:id="@+id/genre" />
 <TextView android:id="@+id/releaseYear" />
 </RelativeLayout>
Parmistech.com
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<Movie> movieList = createMovieList();
ListView = (ListView) findViewById(R.id.list);
CustomListAdapter adapter = new CustomListAdapter(this, movieList);
listView.setAdapter(adapter);
}
}
Parmistech.com
public class CustomListAdapter extends BaseAdapter {
private final Context _context;
private final LayoutInflater _ inflater;
private List<Movie> _items;
}
‫نکته‬:LayoutInflater‫ساختن‬ ‫برای‬‫سیستمی‬ ‫سرویس‬‫یک‬(‫کردن‬‫پر‬)‫یک‬‫نوع‬ ‫از‬‫ی‬ ‫ش‬View‫فایل‬‫روی‬ ‫از‬xml‫متناظرش‬.
‫نکته‬:BaseAdapter‫می‬ ‫را‬ ،‫هایش‬ ‫متد‬‫از‬‫ی‬ ‫بعض‬‫ی‬‫ساز‬ ‫پیاده‬ ‫و‬‫آن‬‫از‬‫بردن‬ ‫ارث‬‫طریق‬ ‫از‬‫ی‬ ‫سفارش‬‫آداپتر‬‫یک‬ ‫ساخت‬‫امکان‬‫که‬ ‫پایه‬‫کالس‬‫یک‬‫دهد‬.
Parmistech.com
@Override
public int getCount() {
return _items == null ? 0 : items.size();
}
@Override
public Object getItem(int position) {
return items == null ? null : items.get(position);
}
@Override
public long getItemId(int position) {
return items == null ? 0 : items.get(position).getId();
}
‫کالس‬‫از‬ ‫ن‬‫چو‬BaseAdapter‫لذا‬ ‫بردیم‬‫ث‬‫ر‬‫ا‬‫مجبور‬‫ی‬ ‫نویس‬‫ز‬‫با‬‫به‬4‫میباشیم‬‫متد‬.‫مهمتر‬ ‫همه‬‫از‬ ‫م‬‫ر‬‫چها‬‫متد‬
‫گردد‬ ‫می‬ ‫معرفی‬‫بعد‬‫اسالید‬ ‫در‬‫که‬‫است‬.
‫نکته‬:Position‫است‬‫لیست‬ ‫درون‬ ‫عنصر‬ ‫موقعیت‬،‫میدهد‬ ‫ار‬‫ر‬‫ق‬‫ما‬ ‫اختیار‬ ‫در‬ ‫متدها‬‫این‬ ‫در‬ ‫اندروید‬‫که‬‫ای‬.‫یک‬،‫صفرم‬ ‫عنصر‬‫مثلن‬‫و‬‫م‬
‫غیره‬ ‫یا‬.‫نام‬ ‫با‬‫کالس‬‫این‬ ‫در‬ ‫که‬‫لیست‬‫عناصر‬ ‫به‬‫میتوانیم‬ ‫موقعیت‬‫شماره‬‫این‬‫داشتن‬ ‫با‬‫ما‬Items‫باشیم‬‫داشته‬‫ی‬ ‫دسترس‬ ،‫اند‬ ‫شده‬‫تعریف‬
(‫متد‬‫طریق‬‫از‬get‫لیست‬‫روی‬ ‫بر‬)
Parmistech.com
@Override
public View getView(int position, View convertView, ViewGroup parent) {
 if (convertView == null)
 convertView = inflater.inflate(R.layout.list_row, null);
// now we can find our item_layout controls - for example:
 ImageView thumb = (ImageView) convertView.findViewById(R.id.thumbnail);
 TextView title = (TextView) convertView.findViewById(R.id.title);
 // whatever we want to bind to our controls - for example :
 title.setText(item.get(position).getTitle();

 return convertView;
{
‫م‬‫ر‬‫چها‬ ‫متد‬ ‫ی‬‫ساز‬ ‫پیاده‬:()getView
‫نکته‬:convertView‫کنید‬ ‫فرض‬‫چیست؟‬15‫دارید‬‫نمایش‬‫ای‬‫ر‬‫ب‬‫آیتم‬.‫لحظه‬‫هر‬ ‫در‬‫شما‬‫موبایل‬‫صفحه‬5‫نمایش‬‫میتواند‬ ‫ا‬‫ر‬ ‫تا‬
‫دهد‬.‫دارند‬‫کردن‬‫اسکرول‬‫به‬ ‫نیاز‬‫مابقی‬.‫متد‬ ‫در‬getView‫تنها‬5convertView‫میشود‬‫ساخته‬.‫همین‬‫از‬ ‫لیست‬‫مابقی‬‫ای‬‫ر‬‫ب‬
5‫میشود‬‫عوض‬ ‫تنها‬‫آن‬‫درون‬‫اطالعات‬ ‫که‬‫اینصورت‬ ‫به‬‫میشود‬ ‫استفاده‬‫تا‬.‫شرط‬‫لذا‬null‫دیگر‬‫ششم‬ ‫عنصر‬‫ای‬‫ر‬‫ب‬ ‫بودن‬False
‫نداریم‬ ‫مجدد‬ ‫ساخت‬‫به‬ ‫نیاز‬ ‫و‬‫برمیگرداند‬.
Parmistech.com
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
 if (convertView == null)
 convertView = inflater.inflate(R.layout.list_row, null);
 holder = new ViewHolder ();
 holder.title = (TextView) convertView.findViewById(R.id.title);
 convertView.setTag(holder);
 } else
 holder = (ViewHolder ) view.getTag();
 hloder.title.setText(item.get(position).getTitle();
 return convertView;
{
‫متد‬ ‫تر‬ ‫امند‬‫ر‬‫کا‬ ‫ی‬‫ساز‬ ‫پیاده‬()getView
‫نکته‬:
‫دستور‬setTag‫یک‬‫ی‬‫نگهدار‬‫ای‬‫ر‬‫ب‬holder‫در‬convertView‫است‬ ‫شده‬ ‫استفاده‬ ‫خودش‬‫با‬‫متناظر‬.‫دستور‬setTag‫متد‬
‫ا‬‫ر‬‫ی‬‫چیز‬‫خواستیم‬ ‫هرجا‬‫که‬ ‫است‬‫عامی‬(‫دیتاتایپی‬‫ازهرنوع‬)‫در‬view‫میکنیم‬ ‫استفاده‬‫نگهداریم‬‫مان‬.
*‫با‬‫آشنایی‬ ‫ای‬‫ر‬‫ب‬ViewHolder‫نمایید‬ ‫مشاهده‬ ‫ا‬‫ر‬‫بعدی‬‫اسالید‬.
Parmistech.com
 static class ViewHolder {

 TextView title;
 TextView genre;
 TextView releaseYear;
 TextView rating;
 ImageView thumb;
}
‫کالس‬ViewHolder
‫نکته‬:ViewHolder‫است‬‫یکسان‬ ‫ها‬‫آیتم‬‫ی‬‫همه‬ ‫قالب‬ ‫چیست؟‬.‫بجای‬‫ما‬ ،‫قبل‬‫مثال‬‫طبق‬‫اگر‬15convertView،5‫میسازیم‬ ‫تا‬.
‫هر‬ ‫در‬ ‫باید‬ ‫ا‬‫ر‬‫چ‬15‫ا‬‫ر‬‫آیتم‬‫آن‬ ‫های‬‫ل‬‫کنتر‬‫بار‬find‫همان‬ ‫ای‬‫ر‬‫ب‬ ‫فقط‬‫اینکار‬‫بجای‬‫کنیم؟‬5‫میدهیم‬‫انجام‬‫ا‬‫ر‬ ‫کار‬‫این‬ ‫تا‬.‫کالس‬‫یک‬‫اینکار‬‫ای‬‫ر‬‫ب‬
‫و‬‫ی‬ ‫سفارش‬static‫نام‬‫به‬ViewHolder‫میسازیم‬.
‫کالس‬‫یف‬‫ر‬‫تع‬ViewHolder‫میشود‬‫تعریف‬ ‫داخلی‬‫بصورت‬(inner class)‫کالس‬ ‫بدنه‬‫داخل‬ ‫در‬‫یعنی‬
CustomLisAdapter‫متد‬‫از‬‫خارج‬‫البته‬ ‫و‬getView!
Parmistech.com
 //inside getView
 Animation animation =
 AnimationUtils.loadAnimation(context, (position > lastPosition )
 ? R.anim.up_from_bottom : R.anim.down_from_top);
 v.startAnimation(animation);
 lastPosition = pos;
‫متد‬‫در‬GetView‫روی‬ ‫بر‬ ‫ا‬‫ر‬‫انیمیشن‬ ‫میتوان‬convertView‫کرد‬ ‫اجرا‬.
‫نکته‬:private int lastPosition = -1;‫کالس‬ ‫ابتدای‬ ‫در‬‫ا‬‫ر‬CustomListAdapter‫کنید‬ ‫اضافه‬.
‫نکته‬:up_from_bottom‫و‬down_from_top‫پسوند‬‫با‬‫انیمیشن‬ ‫فایل‬ ‫دو‬‫نام‬xml‫پوشه‬‫در‬‫که‬‫آست‬anim‫داخل‬
‫پوشه‬res‫گیرد‬ ‫ار‬‫ر‬‫ق‬‫باید‬.
‫انیمیشن‬‫یک‬‫از‬ ‫نمونه‬‫یک‬:
<?xml version="1.0" encoding="utf-8"?>
<translate
android:fromXDelta="90%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="400" />
Parmistech.com

Weitere ähnliche Inhalte

Empfohlen

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Empfohlen (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

آموزش ساخت لیست در اندروید - آموزشگاه پارمیس مشهد

  • 1. ‫ید‬‫و‬‫اندر‬ ‫در‬‫ی‬ ‫ش‬‫ر‬‫سفا‬‫لیست‬ ‫یک‬‫ایجاد‬‫ش‬‫ز‬‫آمو‬ Parmistech.com Ehsan Ghorbannezhad Android Programming - 2014
  • 2. list_row_selector.xml <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/list_row_bg" android:state_pressed="false" android:state_selected="false"/> <item android:drawable="@drawable/list_row_bg_hover" android:state_pressed="true"/> <item android:drawable="@drawable/list_row_bg_hover" android:state_pressed="false" android:state_selected="true"/> </selector> ‫فایل‬‫یک‬ ‫بر‬‫ی‬‫مرور‬selector‫انتخاب‬ ‫هنگام‬ ‫در‬‫لیست‬‫های‬‫آیتم‬ ‫کردت‬ ‫هایالیت‬‫ای‬‫ر‬‫ب‬ Parmistech.com
  • 3.  <RelativeLayout >  <ImageView android:id="@+id/thumbnail" />  <TextView android:id="@+id/title" />  <TextView android:id="@+id/rating"/>  <TextView android:id="@+id/genre" />  <TextView android:id="@+id/releaseYear" />  </RelativeLayout> Parmistech.com
  • 4. public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); List<Movie> movieList = createMovieList(); ListView = (ListView) findViewById(R.id.list); CustomListAdapter adapter = new CustomListAdapter(this, movieList); listView.setAdapter(adapter); } } Parmistech.com
  • 5. public class CustomListAdapter extends BaseAdapter { private final Context _context; private final LayoutInflater _ inflater; private List<Movie> _items; } ‫نکته‬:LayoutInflater‫ساختن‬ ‫برای‬‫سیستمی‬ ‫سرویس‬‫یک‬(‫کردن‬‫پر‬)‫یک‬‫نوع‬ ‫از‬‫ی‬ ‫ش‬View‫فایل‬‫روی‬ ‫از‬xml‫متناظرش‬. ‫نکته‬:BaseAdapter‫می‬ ‫را‬ ،‫هایش‬ ‫متد‬‫از‬‫ی‬ ‫بعض‬‫ی‬‫ساز‬ ‫پیاده‬ ‫و‬‫آن‬‫از‬‫بردن‬ ‫ارث‬‫طریق‬ ‫از‬‫ی‬ ‫سفارش‬‫آداپتر‬‫یک‬ ‫ساخت‬‫امکان‬‫که‬ ‫پایه‬‫کالس‬‫یک‬‫دهد‬. Parmistech.com
  • 6. @Override public int getCount() { return _items == null ? 0 : items.size(); } @Override public Object getItem(int position) { return items == null ? null : items.get(position); } @Override public long getItemId(int position) { return items == null ? 0 : items.get(position).getId(); } ‫کالس‬‫از‬ ‫ن‬‫چو‬BaseAdapter‫لذا‬ ‫بردیم‬‫ث‬‫ر‬‫ا‬‫مجبور‬‫ی‬ ‫نویس‬‫ز‬‫با‬‫به‬4‫میباشیم‬‫متد‬.‫مهمتر‬ ‫همه‬‫از‬ ‫م‬‫ر‬‫چها‬‫متد‬ ‫گردد‬ ‫می‬ ‫معرفی‬‫بعد‬‫اسالید‬ ‫در‬‫که‬‫است‬. ‫نکته‬:Position‫است‬‫لیست‬ ‫درون‬ ‫عنصر‬ ‫موقعیت‬،‫میدهد‬ ‫ار‬‫ر‬‫ق‬‫ما‬ ‫اختیار‬ ‫در‬ ‫متدها‬‫این‬ ‫در‬ ‫اندروید‬‫که‬‫ای‬.‫یک‬،‫صفرم‬ ‫عنصر‬‫مثلن‬‫و‬‫م‬ ‫غیره‬ ‫یا‬.‫نام‬ ‫با‬‫کالس‬‫این‬ ‫در‬ ‫که‬‫لیست‬‫عناصر‬ ‫به‬‫میتوانیم‬ ‫موقعیت‬‫شماره‬‫این‬‫داشتن‬ ‫با‬‫ما‬Items‫باشیم‬‫داشته‬‫ی‬ ‫دسترس‬ ،‫اند‬ ‫شده‬‫تعریف‬ (‫متد‬‫طریق‬‫از‬get‫لیست‬‫روی‬ ‫بر‬) Parmistech.com
  • 7. @Override public View getView(int position, View convertView, ViewGroup parent) {  if (convertView == null)  convertView = inflater.inflate(R.layout.list_row, null); // now we can find our item_layout controls - for example:  ImageView thumb = (ImageView) convertView.findViewById(R.id.thumbnail);  TextView title = (TextView) convertView.findViewById(R.id.title);  // whatever we want to bind to our controls - for example :  title.setText(item.get(position).getTitle();   return convertView; { ‫م‬‫ر‬‫چها‬ ‫متد‬ ‫ی‬‫ساز‬ ‫پیاده‬:()getView ‫نکته‬:convertView‫کنید‬ ‫فرض‬‫چیست؟‬15‫دارید‬‫نمایش‬‫ای‬‫ر‬‫ب‬‫آیتم‬.‫لحظه‬‫هر‬ ‫در‬‫شما‬‫موبایل‬‫صفحه‬5‫نمایش‬‫میتواند‬ ‫ا‬‫ر‬ ‫تا‬ ‫دهد‬.‫دارند‬‫کردن‬‫اسکرول‬‫به‬ ‫نیاز‬‫مابقی‬.‫متد‬ ‫در‬getView‫تنها‬5convertView‫میشود‬‫ساخته‬.‫همین‬‫از‬ ‫لیست‬‫مابقی‬‫ای‬‫ر‬‫ب‬ 5‫میشود‬‫عوض‬ ‫تنها‬‫آن‬‫درون‬‫اطالعات‬ ‫که‬‫اینصورت‬ ‫به‬‫میشود‬ ‫استفاده‬‫تا‬.‫شرط‬‫لذا‬null‫دیگر‬‫ششم‬ ‫عنصر‬‫ای‬‫ر‬‫ب‬ ‫بودن‬False ‫نداریم‬ ‫مجدد‬ ‫ساخت‬‫به‬ ‫نیاز‬ ‫و‬‫برمیگرداند‬. Parmistech.com
  • 8. @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder;  if (convertView == null)  convertView = inflater.inflate(R.layout.list_row, null);  holder = new ViewHolder ();  holder.title = (TextView) convertView.findViewById(R.id.title);  convertView.setTag(holder);  } else  holder = (ViewHolder ) view.getTag();  hloder.title.setText(item.get(position).getTitle();  return convertView; { ‫متد‬ ‫تر‬ ‫امند‬‫ر‬‫کا‬ ‫ی‬‫ساز‬ ‫پیاده‬()getView ‫نکته‬: ‫دستور‬setTag‫یک‬‫ی‬‫نگهدار‬‫ای‬‫ر‬‫ب‬holder‫در‬convertView‫است‬ ‫شده‬ ‫استفاده‬ ‫خودش‬‫با‬‫متناظر‬.‫دستور‬setTag‫متد‬ ‫ا‬‫ر‬‫ی‬‫چیز‬‫خواستیم‬ ‫هرجا‬‫که‬ ‫است‬‫عامی‬(‫دیتاتایپی‬‫ازهرنوع‬)‫در‬view‫میکنیم‬ ‫استفاده‬‫نگهداریم‬‫مان‬. *‫با‬‫آشنایی‬ ‫ای‬‫ر‬‫ب‬ViewHolder‫نمایید‬ ‫مشاهده‬ ‫ا‬‫ر‬‫بعدی‬‫اسالید‬. Parmistech.com
  • 9.  static class ViewHolder {   TextView title;  TextView genre;  TextView releaseYear;  TextView rating;  ImageView thumb; } ‫کالس‬ViewHolder ‫نکته‬:ViewHolder‫است‬‫یکسان‬ ‫ها‬‫آیتم‬‫ی‬‫همه‬ ‫قالب‬ ‫چیست؟‬.‫بجای‬‫ما‬ ،‫قبل‬‫مثال‬‫طبق‬‫اگر‬15convertView،5‫میسازیم‬ ‫تا‬. ‫هر‬ ‫در‬ ‫باید‬ ‫ا‬‫ر‬‫چ‬15‫ا‬‫ر‬‫آیتم‬‫آن‬ ‫های‬‫ل‬‫کنتر‬‫بار‬find‫همان‬ ‫ای‬‫ر‬‫ب‬ ‫فقط‬‫اینکار‬‫بجای‬‫کنیم؟‬5‫میدهیم‬‫انجام‬‫ا‬‫ر‬ ‫کار‬‫این‬ ‫تا‬.‫کالس‬‫یک‬‫اینکار‬‫ای‬‫ر‬‫ب‬ ‫و‬‫ی‬ ‫سفارش‬static‫نام‬‫به‬ViewHolder‫میسازیم‬. ‫کالس‬‫یف‬‫ر‬‫تع‬ViewHolder‫میشود‬‫تعریف‬ ‫داخلی‬‫بصورت‬(inner class)‫کالس‬ ‫بدنه‬‫داخل‬ ‫در‬‫یعنی‬ CustomLisAdapter‫متد‬‫از‬‫خارج‬‫البته‬ ‫و‬getView! Parmistech.com
  • 10.  //inside getView  Animation animation =  AnimationUtils.loadAnimation(context, (position > lastPosition )  ? R.anim.up_from_bottom : R.anim.down_from_top);  v.startAnimation(animation);  lastPosition = pos; ‫متد‬‫در‬GetView‫روی‬ ‫بر‬ ‫ا‬‫ر‬‫انیمیشن‬ ‫میتوان‬convertView‫کرد‬ ‫اجرا‬. ‫نکته‬:private int lastPosition = -1;‫کالس‬ ‫ابتدای‬ ‫در‬‫ا‬‫ر‬CustomListAdapter‫کنید‬ ‫اضافه‬. ‫نکته‬:up_from_bottom‫و‬down_from_top‫پسوند‬‫با‬‫انیمیشن‬ ‫فایل‬ ‫دو‬‫نام‬xml‫پوشه‬‫در‬‫که‬‫آست‬anim‫داخل‬ ‫پوشه‬res‫گیرد‬ ‫ار‬‫ر‬‫ق‬‫باید‬. ‫انیمیشن‬‫یک‬‫از‬ ‫نمونه‬‫یک‬: <?xml version="1.0" encoding="utf-8"?> <translate android:fromXDelta="90%" android:toXDelta="0%" android:fromYDelta="0%" android:toYDelta="0%" android:duration="400" /> Parmistech.com