Android Studio Boshlovchilar uchun(Part 2) "ko`p oynali android ilova dasturini yaratish" 1) Android Studio dasturi ishga tshurilib, birinchi darsda yaratilgan projekt fayillari ochiladi: 2) Bitta yangi "Button" tugmasi qo`yiladi va yuqorida turga "Hello World" deb yozilgan "TextView" companentsai belgilanib "delete" tugmasi yordamida o`chirib yuboriladi (O`chirmasezam buladi shunchaki bizga keragi yo`q bu companentani): "Button" tugmasiga Kirish deb nom beramiz: 3) Chap qisimda joylashgan project fayillari joylashgan "java" papkasi ustida sichqonchaning o`ng tomonini bosib yangi "Empty Activity" hosil qilinadi. Yangi yaratilayotgan "Empty Activity" formasining Java hamda XML fayillari nomlari berilib finish tugmasi bosiladi: Nom sifatida Java fayiliga "SecondActivity" hamda XML fayiliga "activity_second" beriladi. <br><img alt="" src="" style="height:960px; width:1280px" /><br /> 4) "activity_second.xml" fayilida virtual smartfonga bitta "TextView" companentasini qo`yamiz va uning text xsusiyatiga "Salom!! Qanday-Qilib.uz sayiti a`zolari" deb kiritamiz. 5) "FirstApp.java" fayiliga o`tamiz va quydagi amallarni bajaramiz: a) Button toifasidagi yangi "Kirish" deb nomlangan o`zgaruvchini e`lon qilamiz: //Global o`zgaruvchini e`lon qilish Button button, kirish; b) E`lon qilingan o`zgaruvchini "first_app.xml" fayilidagi yangi yaratilgan tugmaga ulanadi: //xml fayilidagi button companentasiga ulash kirish = (Button)findViewById(R.id.button2); c) "kirish" o`zgaruvchisiga biriktirilgan tugmaning bosilish xsusiyati yaratiladi va ikkinchi oynaga o`tish buyrug`i beriladi. //button companentaning bosilish xsusiyatini yaratish: kirish.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(FirstApp.this,SecondActivity.class)); } }); 6) Dasturni apk formatiga o`tkizish tartibi birinchi darsda ko`rsatilgan edi. Ikkinchi darsimizda aynan birinchi darsda yaratilgan project fayillarida ishlaganimiz sababli "apk" fayillarini yaratish uchun dasturni qayta sozlashning hojati yo`q. Birinchi darsda ko`rsatilgan sozlash usuli faqatgina yangi project hosil qilingandagina amalga oshiriladi. Agar bitta project fayilida yaratilgan dasturni "apk" fayillarini olish uchun ikkinchi marotaba qayta sozlanib "apk" fayillari olinsa va smartfonga o`rnatish jarayonida xatolik yuzaga keltirsa, shu project uchun avvalroq olingan apk fayili smartfonga o`rnatilgan bo`ladi va uni smartfoningizdan o`chirib tashlashingiz zarur. bunday muammo yuzaga kelmasligi uchun: "Build --> Generate Signed APK" bosiladi avvalroq (birinchi darsda) kiritilgan shaxsiy parol kiritiladi va "Next --> Finish" tugmalari bosilib apk fayillarini olishimiz mumkun. Uni shaxsiy smartfoningizga o`rnatib sinab ko`rishingiz mumkun. Omad!!! ________________________________________________________________________ ________________________________________________________________________ To`liq Kodlar: ________________________________________________________________________ 1) FirstApp.java fayili uchun: ________________________________________________________________________ package com.example.android.myfirstandroidapp; import android.content.Intent; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; public class FirstApp extends ActionBarActivity { Button button, kirish; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.first_app); button = (Button)findViewById(R.id.button); kirish = (Button)findViewById(R.id.button2); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { XabarChiqarish(); } }); kirish.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(FirstApp.this,SecondActivity.class)); } }); } public void XabarChiqarish(){ Toast.makeText(FirstApp.this, "Salom 'Qanday-Qilib.uz sayiti A`zolari!!'", Toast.LENGTH_SHORT).show(); } } ________________________________________________________________________ 2) SecondActivity.java fayili uchun: ________________________________________________________________________ package com.example.android.myfirstandroidapp; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; public class SecondActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); } } ________________________________________________________________________ 3) first_app.xml fayili uchun: ________________________________________________________________________ <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="