onViewCreated() usuli bajarilganda, ko'rinish allaqachon yaratilgan va u birinchi parametr - View obyekti sifatida uzatiladi, bu orqali identifikatorlar yordamida biz Visual elementlarni - TextView va Button olishimiz mumkin. ko'rinish.
Qolgan umr tsikli usullari uchun oddiy jurnallar Log.d() usuli yordamida o'rnatiladi.
activity_main.xml fayliga fragment qo'shamiz:
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.fragmentapp.ContentFragment" />
Va MainActivity klassi:
package com.example.fragmentapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Agar biz loyihani ishga tushirsak, u holda qurilma ekranida biz fragment uchun aniqlangan vizual interfeysni ko'ramiz.
Va Android Studio dagi Logcat oynasida siz hayot aylanishi usullarini hisobga olishni kuzatishingiz mumkin.
Do'stlaringiz bilan baham: |