Laboratoriya ishi №6
Laboratoriyaning amaliy qismi
Download 19.46 Kb.
|
Laboratoriya ishi-6
- Bu sahifa navigatsiya:
- Laboratoriya ishlarini bajarish uchun topshiriqlar
Laboratoriyaning amaliy qismi
Agar standart holatda biz XML faylni setContentView(R.layout.activity_main) usuliga qo‘shsak, uni dasturiy jihatdan yaratishda bizga bu usul kerak bo‘lmaydi. Uni o‘chiring va kodni yozing: paket en.alexanderkimov.test; android.app.Activity import;
umumiy sinf TestActivity faollikni kengaytiradi { /** Faoliyat birinchi marta yaratilganda chaqiriladi. */
// setContentView(R.layout.activity_test); LinearLayout layout = yangi LinearLayout(TestActivity.this); layout.setId(R.id.layout_id); LayoutParams layoutParams = yangi LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); layout.setLayoutParams(layoutParams); layout.setOrientation(LinearLayout.VERTICAL); ImageView imageView = new ImageView(TestActivity.this); imageView.setId(R.id.image_id); imageView.setImageResource(R.drawable.ic_launcher); LayoutParams imageViewLayoutParams = yangi LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); imageView.setLayoutParams(imageViewLayoutParams); layout.addView (imageView); setContentView (tartib); layout.setOnClickListener(onViewClickListener); imageView.setOnClickListener(onViewClickListener); } onClickListener onViewClickListener = yangi OnClickListener() { @Override public void onClick(View v) { int myId = v.getId(); Toast.makeText(TestActivity.this, "ID: " + String.valueOf(myId) + " bosildi", Toast.LENGTH_LONG).show(); } }; } Shakllanish printsipi quyidagicha - biz LinearLayout ob'ektini (yoki boshqa konteyner) yaratamiz va kerakli xususiyatlarni o‘rnatamiz. Keyinchalik, biz kerakli bolalar elementlarini yaratamiz va ularning xususiyatlarini o‘rnatamiz. AddView() usuli orqali bola elementni asosiy elementga ulashni unutmang. Laboratoriya ishlarini bajarish uchun topshiriqlar Rus tilidan o‘zbek tiliga “lug‘at” tipidagi tarjima dasturini ishlab chiqish. Kirish sifatida massivni (har qanday turdagi) qabul qiluvchi filtr usulini va massivdan ortiqchani olib tashlash uchun application(Object o) usuli bilan Filtr interfeysini amalga oshirishni yozing. Satrlar yoki boshqa ob'ektlarda qanday ishlashini tekshiring. Download 19.46 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling