SlideShare a Scribd company logo
‫مهربان‬ ‫بخشنده‬ ‫خداوند‬ ‫نام‬ ‫به‬
‫برنامه‬‫در‬ ‫ایستا‬ ‫نویسی‬‫اندروید‬‫استودیو‬
‫حیدری‬ ‫محمد‬
‫اطالعات‬ ‫فناوری‬ ‫مهندسی‬ ‫ارشد‬–‫تهران‬ ‫بهشتی‬ ‫شهید‬ ‫دانشگاه‬
1
‫آرایه‬ ‫انواع‬
2
DynamicStatic
3
4691ruopismahS
‫کاراکتر‬ ‫یک‬
‫استاتیک‬ ‫آرایه‬
‫آرایه‬ ‫نوع‬‫آن‬ ‫نام‬ ‫سپس‬ ‫میشود‬ ‫تعریف‬ ‫ابتدا‬ ‫در‬
String ClassNames[ ] = { “Activity1” , “Activity2” , …} ;
‫مقادیر‬ ‫به‬ ‫دسترسی‬:
ClassName[0]
‫ذخیره‬String‫در‬Shared Preferences
4
SharedPrefernces sharedprefernces =
getSharedPrefernces(MyPREFERNCES, Context, MODE_PRIVATE);
String SIT = sharedPrefernces.getString(‘name’);
SharedPrefernces .Editor editor = SharedPrefernces.edit();
editor.putString(name, n);
editor.PutString(Phone, ph);
editor.Commit();
‫همانند‬
‫در‬ ‫رجیستری‬
‫است‬ ‫ویندوز‬
‫فایل‬ ‫یک‬
XML‫برای‬
‫رشت‬ ‫میزبانی‬‫ه‬
‫آرایه‬ ‫و‬ ‫ها‬
‫هاست‬
‫کالس‬StringUtils
5
IsEmpty/IsBlank Trim/Strip Equals/Compare StartsWith
endsWith ContainsOnly ContiansNone ContainsAny
DefaultString IsAlpha IsNumeric IsWhiteSpace
‫فایل‬String.xml
6
‫مسیر‬ ‫در‬res/values‫فایلی‬‫نام‬ ‫با‬strings.xml‫می‬ ‫ها‬ ‫رشته‬ ‫تعریف‬ ‫مختص‬ ‫که‬ ‫شده‬ ‫تعبیه‬‫باشد‬:
7
‫ها‬ ‫آرایه‬ ‫با‬ ‫کار‬
‫ب‬‫دست‬‫فایل‬ ‫در‬ ‫شده‬ ‫تعریف‬ ‫های‬ ‫رشته‬ ‫تمامی‬ ‫نام‬ ‫آوردن‬String.xml‫جنس‬ ‫از‬ ‫آرایه‬ ‫صورت‬ ‫به‬String
Field[ ] fields = R.string.class.getFields();
String[ ] allStringsNames = new String[fields.length];
for (int i =0; i < fields.length; i++) {
allStringsNames[i] = fields[i].getName();
‫ایمپورت‬‫نشود‬ ‫فراموش‬ ‫جاوا‬ ‫پیکج‬
import java.lang.reflect.Field;
‫کردن‬ ‫اضافه‬List View
8
‫پوشه‬Layout‫کنید‬ ‫باز‬ ‫را‬
‫کردن‬ ‫باز‬‫فایل‬
activity_list.xml
andriod:id="@id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"&amp;amp;gt;
‫می‬ ‫جاوا‬ ‫فایل‬ ‫در‬ ‫آن‬ ‫معرفی‬ ‫به‬ ‫نوبت‬ ‫ویو‬ ‫لیست‬ ‫کردن‬ ‫اضافه‬ ‫از‬ ‫بعد‬‫رسد‬
9
‫جاوا‬ ‫فایل‬ ‫در‬ ‫ویو‬ ‫لیست‬ ‫معرفی‬
10
JAVA
Folder
Open
List.Java
Define
Variable
ListView list
‫ذیل‬ ‫کد‬ ‫نوشتن‬
‫متد‬ ‫در‬
OnCreate
list = (ListView) findViewById(R.id.listView); ‫کد‬‫مربوطه‬‫لیست‬‫ویو‬‫مورد‬‫نظر‬‫را‬‫پیدا‬‫میکند‬‫و‬‫آن‬‫را‬‫به‬‫متغییر‬‫لیست‬‫مرتب‬‫ط‬‫می‬‫کند‬.
‫عملیات‬ ‫عسل‬ ‫ماه‬
11
Array Adapter
12
Data
Source
Adapter
Adapter
View
‫آرای‬ ‫آداپتور‬ ‫وظیفه‬‫ه‬
‫؟‬ ‫چیست‬
‫آرایه‬ ‫از‬ ‫را‬ ‫اطالعات‬
‫میگیرد‬
‫در‬ ‫مستقیما‬View
‫میدهد‬ ‫نمایش‬
‫کالس‬ArrayAdapter
13
‫کالس‬ ‫تعریف‬
‫به‬ ‫اتصال‬List View
‫کد‬ ‫قطعه‬ ‫تشریح‬
14
This ‫به‬List.Java‫میکند‬ ‫اشاره‬
simple_list
_item_1
‫شکل‬ ‫به‬List View‫میکند‬ ‫اشاره‬
Items
‫میکند‬ ‫اشاره‬ ‫مربوطه‬ ‫کالس‬ ‫به‬
‫رشته‬ ‫یک‬ ‫مقدار‬ ‫کردن‬ ‫چک‬string،‫با‬equals
15
if(myString=="string_to_check"){
// some commands
}
Force Close
‫صحیح‬ ‫شیوه‬
if(myString.equals("string_to_check")){
// some commands
}
‫رشته‬ ‫یک‬ ‫دریافت‬string‫از‬‫فایل‬strings.xml
16
‫برای‬‫فایل‬ ‫از‬ ‫را‬ ‫رشته‬ ‫این‬ ‫بتوانیم‬ ‫اینکه‬strings.xml،‫نویسیم‬ ‫می‬ ‫را‬ ‫زیر‬ ‫کدهای‬ ،‫نماییم‬ ‫استفاده‬ ‫و‬ ‫کرده‬ ‫فراخوانی‬:
‫فایل‬ ‫از‬ ‫را‬ ‫رشته‬ ،‫باال‬ ‫کد‬ ‫در‬strings.xml‫فراخوانی‬‫نام‬ ‫به‬ ‫متغیری‬ ‫در‬ ‫سپس‬ ‫و‬ ‫کرده‬my_string‫ذخیره‬‫از‬ ‫توان‬ ‫می‬ ،‫بعد‬ ‫به‬ ‫این‬ ‫از‬ ‫که‬ ‫ایم‬ ‫کرده‬
‫استفاده‬ ‫آن‬‫نمود‬
‫نیز‬ ‫زیر‬ ‫تابع‬ ‫از‬ ‫استفاده‬ ‫با‬‫رشته‬ ‫میتوان‬strings‫فراخوانی‬ ‫را‬ ‫نظر‬ ‫مورد‬‫کنیم‬.
‫رشته‬ ‫یک‬ ‫خواندن‬Strings‫فایل‬ ‫از‬strings.xml،‫که‬ ‫صورتی‬ ‫در‬ ‫تنها‬
‫فایل‬ ‫در‬ ‫نظر‬ ‫مورد‬ ‫رشته‬strings.xml،‫باشد‬ ‫شده‬ ‫تعریف‬
int identifier =
getResources().getIdentifier("string_name","string","your.package.name");
if (identifier!=0)
{
String str = getResources().getString(identifier);
}else
{
String str = "";
}
17
‫به‬ ‫ارجاع‬id‫یک‬TextView،‫رشته‬ ‫تعریف‬ ‫با‬string
18
String textId = “myTextView”;
int resID = getResources().getIdentifier(textId , “id”, getPackageName());
TextView tv = (TextView) findViewById(resID);
package.name
‫نام‬package‫برنامه‬
‫باشد‬ ‫می‬ ‫اندروید‬
myTextView
id‫برای‬ ‫شده‬ ‫تعریف‬
TextView
‫یک‬ ‫در‬ ‫شده‬ ‫داده‬ ‫نمایش‬ ‫متن‬ ‫دریافت‬TextView‫جدید‬ ‫متغیر‬ ‫یک‬ ‫در‬ ‫آن‬ ‫ذخیره‬ ‫و‬
19
‫یک‬ ‫در‬ ‫شده‬ ‫داده‬ ‫نمایش‬ ‫متن‬ ‫توانیم‬ ‫می‬ ‫ما‬TextView‫رشته‬ ‫نوع‬ ‫از‬ ‫جدید‬ ‫متغیر‬ ‫یک‬ ‫در‬ ‫و‬ ‫کرده‬ ‫دریافت‬ ‫را‬String‫کنیم‬ ‫ذخیره‬
TextView tv = (TextView) findViewById(R.id.textView1);
String text = tv.getText().toString();
20
Field[] fields = R.string.class.getFields();
String[] allStringsNames = new String[fields.length];
for (int i =0; i < fields.length; i++) {
allStringsNames[i] = fields[i].getName();
}
‫نشود‬ ‫فراموش‬ ‫جاوا‬ ‫پکیج‬ ‫ایمپورت‬
import java.lang.reflect.Field;
‫های‬ ‫رشته‬ ‫تمامی‬ ‫نام‬ ‫آوردن‬ ‫دست‬ ‫به‬‫تعریف‬‫فایل‬ ‫در‬ ‫شده‬strings.xml‫به‬‫یک‬ ‫صورت‬‫آرایه‬
‫ها‬ ‫رشته‬ ‫از‬ ‫ای‬ ‫آرایه‬ ‫تعریف‬string array‫در‬‫فایل‬strings.xml
21
‫متغیر‬ ‫تبدیل‬int‫به‬‫متغیر‬String‫بالعکس‬ ‫و‬
22
int SIT_Tasis = 1964;
String SIT = String.valueOf(num);
String str = "1234";
int num = Integer.parseInt(str);
‫خالی‬ ‫فضاهای‬ ‫حذف‬‫کاراکترهای‬space‫رشته‬ ‫یک‬ ‫انتهای‬ ‫و‬ ‫ابتدا‬String،‫روش‬ ‫با‬trim
‫با‬ ‫رشته‬ ‫یک‬ ‫کاراکترهای‬ ‫تعداد‬ ‫آوردن‬ ‫دست‬ ‫به‬length
23
String str_1 = " www.Shamsipour.ac.ir ";
String str_2 = str_1.trim();
String SIT = “shamsipour.tvu.ac.ir”
Int num = str.length();
‫مقدار‬20‫میشود‬ ‫دخیره‬
String Str = “Shamsipour.ac.ir”
Boolean b = str.contains(“Sha”)
‫رشته‬ ‫یک‬ ‫داشتن‬ ‫وجود‬ ‫کردن‬ ‫چک‬‫در‬‫روش‬ ‫با‬ ،‫دیگر‬ ‫ای‬ ‫رشته‬contains
24
b TRUE
‫آرایه‬ ‫یک‬ ‫ارسال‬Array‫از‬‫رشته‬ ‫نوع‬‫از‬‫یک‬Activity‫به‬Activity‫دیگر‬
25
‫درون‬Activity‫می‬ ‫را‬ ‫زیر‬ ‫کدهای‬ ،‫اول‬‫نویسیم‬:
String myArray_1[ ] = {"ali","hamed","reza"};
Intent intent = new Intent(getApplicationContext(), NewActivity.class);
intent.putExtra("key_name", myArray_1);
startActivity(intent);
‫درون‬ ‫سپس‬Activity‫دوم‬‫بنویسیم‬ ‫را‬ ‫زیر‬ ‫کدهای‬ ‫باید‬ ،:
Bundle extras = getIntent().getExtras();
if (extras != null) {
String[] myArray_2 = extras.getStringArray("key_name");
}
26
‫آرایه‬ ‫یک‬ ‫ارسال‬‫از‬‫رشته‬ ‫از‬ ‫غیر‬ ‫نوعی‬‫عدد‬ ‫یا‬
‫در‬Activity،‫دوم‬‫برای‬‫دریافت‬‫رشته‬،‫از‬‫روش‬getStringArray‫و‬‫برای‬‫دریافت‬‫عدد‬‫از‬‫روش‬getIntArray‫استفاده‬‫شد‬.
‫بنابراین‬‫برای‬‫هر‬‫نوع‬،‫متغیر‬‫باید‬‫تنها‬‫روش‬method‫مربوط‬‫به‬‫آن‬‫را‬‫بدانیم‬
‫نشانگر‬‫موس‬‫را‬‫بعد‬‫از‬‫عبارت‬extras.get‫برده‬‫کلیک‬‫می‬‫کنیم‬‫تا‬‫نشانگر‬‫در‬‫آنجا‬‫قرار‬‫بگیرد‬‫و‬‫کلیدهای‬Ctrl‫و‬Space‫را‬‫به‬‫صورت‬
‫همزمان‬‫از‬‫کیبورد‬‫فشار‬‫می‬‫دهیم‬‫تا‬‫تمامی‬‫روش‬‫های‬‫قابل‬،‫انتخاب‬‫نمایش‬‫داده‬‫شوند‬:
‫دار‬ ‫قرار‬ ‫مشخص‬ ‫کاراکتر‬ ‫یک‬ ‫از‬ ‫پس‬ ‫که‬ ‫متن‬ ‫یک‬ ‫از‬ ‫قسمتی‬ ‫گرفتن‬‫د‬
27
‫دانلود‬ ‫لینک‬ ‫روی‬ ‫از‬ ‫فایل‬ ‫نوع‬ ‫تشخیص‬:
String SURL = tvu.ac.ir/Song.mp3
Int Position_SURL = SURL.lastIndexOf(".");
(.)‫کاراکتر‬ ‫آخرین‬ ‫مکان‬ ‫آوردن‬ ‫بدست‬
String TypeFile = SURL.substring(Position_SURL, Position_SURL + 4);
‫کاراکتر‬ ‫مکان‬ ‫از‬ ‫را‬ ‫مقادیر‬).(‫ذخیره‬ ‫متغیر‬ ‫در‬ ‫کاراکتر‬ ‫چهار‬ ‫تا‬‫کن‬
‫مقدار‬ ‫نهایت‬ ‫در‬mp3‫متغیر‬ ‫در‬TypeFile‫شد‬ ‫خواهد‬ ‫ذخیره‬.

More Related Content

Featured

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
Neil 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 2024
Albert 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 Insights
Kurio // 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 2024
Search 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 summary
SpeakerHub
 
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 Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit 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 management
MindGenius
 
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 Work
GetSmarter
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
Alireza Esmikhani
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago
 

Featured (20)

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
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

برنامه نویسی ایستا و کار با رشته ها و آرایه ها در اندروید

  • 1. ‫مهربان‬ ‫بخشنده‬ ‫خداوند‬ ‫نام‬ ‫به‬ ‫برنامه‬‫در‬ ‫ایستا‬ ‫نویسی‬‫اندروید‬‫استودیو‬ ‫حیدری‬ ‫محمد‬ ‫اطالعات‬ ‫فناوری‬ ‫مهندسی‬ ‫ارشد‬–‫تهران‬ ‫بهشتی‬ ‫شهید‬ ‫دانشگاه‬ 1
  • 3. 3 4691ruopismahS ‫کاراکتر‬ ‫یک‬ ‫استاتیک‬ ‫آرایه‬ ‫آرایه‬ ‫نوع‬‫آن‬ ‫نام‬ ‫سپس‬ ‫میشود‬ ‫تعریف‬ ‫ابتدا‬ ‫در‬ String ClassNames[ ] = { “Activity1” , “Activity2” , …} ; ‫مقادیر‬ ‫به‬ ‫دسترسی‬: ClassName[0]
  • 4. ‫ذخیره‬String‫در‬Shared Preferences 4 SharedPrefernces sharedprefernces = getSharedPrefernces(MyPREFERNCES, Context, MODE_PRIVATE); String SIT = sharedPrefernces.getString(‘name’); SharedPrefernces .Editor editor = SharedPrefernces.edit(); editor.putString(name, n); editor.PutString(Phone, ph); editor.Commit(); ‫همانند‬ ‫در‬ ‫رجیستری‬ ‫است‬ ‫ویندوز‬ ‫فایل‬ ‫یک‬ XML‫برای‬ ‫رشت‬ ‫میزبانی‬‫ه‬ ‫آرایه‬ ‫و‬ ‫ها‬ ‫هاست‬
  • 5. ‫کالس‬StringUtils 5 IsEmpty/IsBlank Trim/Strip Equals/Compare StartsWith endsWith ContainsOnly ContiansNone ContainsAny DefaultString IsAlpha IsNumeric IsWhiteSpace
  • 6. ‫فایل‬String.xml 6 ‫مسیر‬ ‫در‬res/values‫فایلی‬‫نام‬ ‫با‬strings.xml‫می‬ ‫ها‬ ‫رشته‬ ‫تعریف‬ ‫مختص‬ ‫که‬ ‫شده‬ ‫تعبیه‬‫باشد‬:
  • 7. 7 ‫ها‬ ‫آرایه‬ ‫با‬ ‫کار‬ ‫ب‬‫دست‬‫فایل‬ ‫در‬ ‫شده‬ ‫تعریف‬ ‫های‬ ‫رشته‬ ‫تمامی‬ ‫نام‬ ‫آوردن‬String.xml‫جنس‬ ‫از‬ ‫آرایه‬ ‫صورت‬ ‫به‬String Field[ ] fields = R.string.class.getFields(); String[ ] allStringsNames = new String[fields.length]; for (int i =0; i < fields.length; i++) { allStringsNames[i] = fields[i].getName(); ‫ایمپورت‬‫نشود‬ ‫فراموش‬ ‫جاوا‬ ‫پیکج‬ import java.lang.reflect.Field;
  • 8. ‫کردن‬ ‫اضافه‬List View 8 ‫پوشه‬Layout‫کنید‬ ‫باز‬ ‫را‬ ‫کردن‬ ‫باز‬‫فایل‬ activity_list.xml andriod:id="@id/listView" android:layout_width="match_parent" android:layout_height="match_parent"&amp;amp;gt;
  • 9. ‫می‬ ‫جاوا‬ ‫فایل‬ ‫در‬ ‫آن‬ ‫معرفی‬ ‫به‬ ‫نوبت‬ ‫ویو‬ ‫لیست‬ ‫کردن‬ ‫اضافه‬ ‫از‬ ‫بعد‬‫رسد‬ 9
  • 10. ‫جاوا‬ ‫فایل‬ ‫در‬ ‫ویو‬ ‫لیست‬ ‫معرفی‬ 10 JAVA Folder Open List.Java Define Variable ListView list ‫ذیل‬ ‫کد‬ ‫نوشتن‬ ‫متد‬ ‫در‬ OnCreate list = (ListView) findViewById(R.id.listView); ‫کد‬‫مربوطه‬‫لیست‬‫ویو‬‫مورد‬‫نظر‬‫را‬‫پیدا‬‫میکند‬‫و‬‫آن‬‫را‬‫به‬‫متغییر‬‫لیست‬‫مرتب‬‫ط‬‫می‬‫کند‬.
  • 12. Array Adapter 12 Data Source Adapter Adapter View ‫آرای‬ ‫آداپتور‬ ‫وظیفه‬‫ه‬ ‫؟‬ ‫چیست‬ ‫آرایه‬ ‫از‬ ‫را‬ ‫اطالعات‬ ‫میگیرد‬ ‫در‬ ‫مستقیما‬View ‫میدهد‬ ‫نمایش‬
  • 14. ‫کد‬ ‫قطعه‬ ‫تشریح‬ 14 This ‫به‬List.Java‫میکند‬ ‫اشاره‬ simple_list _item_1 ‫شکل‬ ‫به‬List View‫میکند‬ ‫اشاره‬ Items ‫میکند‬ ‫اشاره‬ ‫مربوطه‬ ‫کالس‬ ‫به‬
  • 15. ‫رشته‬ ‫یک‬ ‫مقدار‬ ‫کردن‬ ‫چک‬string،‫با‬equals 15 if(myString=="string_to_check"){ // some commands } Force Close ‫صحیح‬ ‫شیوه‬ if(myString.equals("string_to_check")){ // some commands }
  • 16. ‫رشته‬ ‫یک‬ ‫دریافت‬string‫از‬‫فایل‬strings.xml 16 ‫برای‬‫فایل‬ ‫از‬ ‫را‬ ‫رشته‬ ‫این‬ ‫بتوانیم‬ ‫اینکه‬strings.xml،‫نویسیم‬ ‫می‬ ‫را‬ ‫زیر‬ ‫کدهای‬ ،‫نماییم‬ ‫استفاده‬ ‫و‬ ‫کرده‬ ‫فراخوانی‬: ‫فایل‬ ‫از‬ ‫را‬ ‫رشته‬ ،‫باال‬ ‫کد‬ ‫در‬strings.xml‫فراخوانی‬‫نام‬ ‫به‬ ‫متغیری‬ ‫در‬ ‫سپس‬ ‫و‬ ‫کرده‬my_string‫ذخیره‬‫از‬ ‫توان‬ ‫می‬ ،‫بعد‬ ‫به‬ ‫این‬ ‫از‬ ‫که‬ ‫ایم‬ ‫کرده‬ ‫استفاده‬ ‫آن‬‫نمود‬ ‫نیز‬ ‫زیر‬ ‫تابع‬ ‫از‬ ‫استفاده‬ ‫با‬‫رشته‬ ‫میتوان‬strings‫فراخوانی‬ ‫را‬ ‫نظر‬ ‫مورد‬‫کنیم‬.
  • 17. ‫رشته‬ ‫یک‬ ‫خواندن‬Strings‫فایل‬ ‫از‬strings.xml،‫که‬ ‫صورتی‬ ‫در‬ ‫تنها‬ ‫فایل‬ ‫در‬ ‫نظر‬ ‫مورد‬ ‫رشته‬strings.xml،‫باشد‬ ‫شده‬ ‫تعریف‬ int identifier = getResources().getIdentifier("string_name","string","your.package.name"); if (identifier!=0) { String str = getResources().getString(identifier); }else { String str = ""; } 17
  • 18. ‫به‬ ‫ارجاع‬id‫یک‬TextView،‫رشته‬ ‫تعریف‬ ‫با‬string 18 String textId = “myTextView”; int resID = getResources().getIdentifier(textId , “id”, getPackageName()); TextView tv = (TextView) findViewById(resID); package.name ‫نام‬package‫برنامه‬ ‫باشد‬ ‫می‬ ‫اندروید‬ myTextView id‫برای‬ ‫شده‬ ‫تعریف‬ TextView
  • 19. ‫یک‬ ‫در‬ ‫شده‬ ‫داده‬ ‫نمایش‬ ‫متن‬ ‫دریافت‬TextView‫جدید‬ ‫متغیر‬ ‫یک‬ ‫در‬ ‫آن‬ ‫ذخیره‬ ‫و‬ 19 ‫یک‬ ‫در‬ ‫شده‬ ‫داده‬ ‫نمایش‬ ‫متن‬ ‫توانیم‬ ‫می‬ ‫ما‬TextView‫رشته‬ ‫نوع‬ ‫از‬ ‫جدید‬ ‫متغیر‬ ‫یک‬ ‫در‬ ‫و‬ ‫کرده‬ ‫دریافت‬ ‫را‬String‫کنیم‬ ‫ذخیره‬ TextView tv = (TextView) findViewById(R.id.textView1); String text = tv.getText().toString();
  • 20. 20 Field[] fields = R.string.class.getFields(); String[] allStringsNames = new String[fields.length]; for (int i =0; i < fields.length; i++) { allStringsNames[i] = fields[i].getName(); } ‫نشود‬ ‫فراموش‬ ‫جاوا‬ ‫پکیج‬ ‫ایمپورت‬ import java.lang.reflect.Field; ‫های‬ ‫رشته‬ ‫تمامی‬ ‫نام‬ ‫آوردن‬ ‫دست‬ ‫به‬‫تعریف‬‫فایل‬ ‫در‬ ‫شده‬strings.xml‫به‬‫یک‬ ‫صورت‬‫آرایه‬
  • 21. ‫ها‬ ‫رشته‬ ‫از‬ ‫ای‬ ‫آرایه‬ ‫تعریف‬string array‫در‬‫فایل‬strings.xml 21
  • 22. ‫متغیر‬ ‫تبدیل‬int‫به‬‫متغیر‬String‫بالعکس‬ ‫و‬ 22 int SIT_Tasis = 1964; String SIT = String.valueOf(num); String str = "1234"; int num = Integer.parseInt(str);
  • 23. ‫خالی‬ ‫فضاهای‬ ‫حذف‬‫کاراکترهای‬space‫رشته‬ ‫یک‬ ‫انتهای‬ ‫و‬ ‫ابتدا‬String،‫روش‬ ‫با‬trim ‫با‬ ‫رشته‬ ‫یک‬ ‫کاراکترهای‬ ‫تعداد‬ ‫آوردن‬ ‫دست‬ ‫به‬length 23 String str_1 = " www.Shamsipour.ac.ir "; String str_2 = str_1.trim(); String SIT = “shamsipour.tvu.ac.ir” Int num = str.length(); ‫مقدار‬20‫میشود‬ ‫دخیره‬
  • 24. String Str = “Shamsipour.ac.ir” Boolean b = str.contains(“Sha”) ‫رشته‬ ‫یک‬ ‫داشتن‬ ‫وجود‬ ‫کردن‬ ‫چک‬‫در‬‫روش‬ ‫با‬ ،‫دیگر‬ ‫ای‬ ‫رشته‬contains 24 b TRUE
  • 25. ‫آرایه‬ ‫یک‬ ‫ارسال‬Array‫از‬‫رشته‬ ‫نوع‬‫از‬‫یک‬Activity‫به‬Activity‫دیگر‬ 25 ‫درون‬Activity‫می‬ ‫را‬ ‫زیر‬ ‫کدهای‬ ،‫اول‬‫نویسیم‬: String myArray_1[ ] = {"ali","hamed","reza"}; Intent intent = new Intent(getApplicationContext(), NewActivity.class); intent.putExtra("key_name", myArray_1); startActivity(intent); ‫درون‬ ‫سپس‬Activity‫دوم‬‫بنویسیم‬ ‫را‬ ‫زیر‬ ‫کدهای‬ ‫باید‬ ،: Bundle extras = getIntent().getExtras(); if (extras != null) { String[] myArray_2 = extras.getStringArray("key_name"); }
  • 26. 26 ‫آرایه‬ ‫یک‬ ‫ارسال‬‫از‬‫رشته‬ ‫از‬ ‫غیر‬ ‫نوعی‬‫عدد‬ ‫یا‬ ‫در‬Activity،‫دوم‬‫برای‬‫دریافت‬‫رشته‬،‫از‬‫روش‬getStringArray‫و‬‫برای‬‫دریافت‬‫عدد‬‫از‬‫روش‬getIntArray‫استفاده‬‫شد‬. ‫بنابراین‬‫برای‬‫هر‬‫نوع‬،‫متغیر‬‫باید‬‫تنها‬‫روش‬method‫مربوط‬‫به‬‫آن‬‫را‬‫بدانیم‬ ‫نشانگر‬‫موس‬‫را‬‫بعد‬‫از‬‫عبارت‬extras.get‫برده‬‫کلیک‬‫می‬‫کنیم‬‫تا‬‫نشانگر‬‫در‬‫آنجا‬‫قرار‬‫بگیرد‬‫و‬‫کلیدهای‬Ctrl‫و‬Space‫را‬‫به‬‫صورت‬ ‫همزمان‬‫از‬‫کیبورد‬‫فشار‬‫می‬‫دهیم‬‫تا‬‫تمامی‬‫روش‬‫های‬‫قابل‬،‫انتخاب‬‫نمایش‬‫داده‬‫شوند‬:
  • 27. ‫دار‬ ‫قرار‬ ‫مشخص‬ ‫کاراکتر‬ ‫یک‬ ‫از‬ ‫پس‬ ‫که‬ ‫متن‬ ‫یک‬ ‫از‬ ‫قسمتی‬ ‫گرفتن‬‫د‬ 27 ‫دانلود‬ ‫لینک‬ ‫روی‬ ‫از‬ ‫فایل‬ ‫نوع‬ ‫تشخیص‬: String SURL = tvu.ac.ir/Song.mp3 Int Position_SURL = SURL.lastIndexOf("."); (.)‫کاراکتر‬ ‫آخرین‬ ‫مکان‬ ‫آوردن‬ ‫بدست‬ String TypeFile = SURL.substring(Position_SURL, Position_SURL + 4); ‫کاراکتر‬ ‫مکان‬ ‫از‬ ‫را‬ ‫مقادیر‬).(‫ذخیره‬ ‫متغیر‬ ‫در‬ ‫کاراکتر‬ ‫چهار‬ ‫تا‬‫کن‬ ‫مقدار‬ ‫نهایت‬ ‫در‬mp3‫متغیر‬ ‫در‬TypeFile‫شد‬ ‫خواهد‬ ‫ذخیره‬.