Emulyatorni sozlang, yangi loyiha yarating


textView , getResources().getStringArray(R.array. images


Download 92.99 Kb.
Pdf ko'rish
bet12/14
Sana30.04.2023
Hajmi92.99 Kb.
#1417261
1   ...   6   7   8   9   10   11   12   13   14
Bog'liq
620-20 K.Temirov compressed

textView
,
getResources().getStringArray(R.array.
images
)));
Keyinchalik, MainActivity sinfida MyAdapter sinfini yarating:
public class
MyAdapter
extends
ArrayAdapter {
public
MyAdapter(Context context,
int
resource,
int
textViewResourceId, String[] string){
super
(context, resource, textViewResourceId, string);
}
@Override
public
View getView(
int
position, View convertView,
ViewGroup parent){
LayoutInflater inflater = (LayoutInflater)
getSystemService(Context.
LAYOUT_INFLATER_SERVICE
);
View row = inflater.inflate(R.layout.


list_item
, parent,
false
);
String[] items =
getResources().getStringArray(R.array.
images
);
ImageView image = (ImageView)
row.findViewById(R.id.
imageView
);
TextView text = (TextView)
row.findViewById(R.id.
textView
);
text.setText(items[position]);
return
row;
}
}
Ammo bu hammasi emas. 
Har bir satrda unga mos keladigan rasm bo'lishi uchun switch-case dizaynini yaratish
kerak. Qaytish qatoridan oldin
quyidagi kodni kiriting:
switch
(items[position]) {
case
"Image 1"
:
image.setImageResource(R.drawable.image1);
break
;
case
"Image 2"
:
image.setImageResource(R.drawable.image2);
break
;
case
"Image 3"
:


image.setImageResource(R.drawable.image3);

Download 92.99 Kb.

Do'stlaringiz bilan baham:
1   ...   6   7   8   9   10   11   12   13   14




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling