Laboratoriya ishi №16 Mavzu: Voqealar (intents)


// replace the FrameLayout with new Fragment


Download 444.29 Kb.
Pdf ko'rish
bet7/15
Sana14.12.2022
Hajmi444.29 Kb.
#1004913
1   2   3   4   5   6   7   8   9   10   ...   15
Bog'liq
Abduraximov Elbek 612 19 guruh, 4 deadline

// replace the FrameLayout with new Fragment 
fragmentTransaction.replace(R.id.frameLayout, fragment); 
fragmentTransaction.commit(); // save the changes 


Endi bizga 2 ta fragment va 2 xml maket kerak. Shunday qilib, paket papkangizni 
o'ng tugmasini bosib ikkita bo'lak yarating va sinflarni yarating va ularni 
FirstFragment va SecondFragment deb nomlang va mos ravishda quyidagi kodni 
qo'shing. 
FirstFragment.class 
Ushbu fragmentda biz birinchi navbatda tartibni kengaytiramiz va tugmachaning 
havolasini olamiz. Shundan so'ng biz Tugmachada setOnClickListener hodisasini 
amalga oshiramiz, shuning uchun foydalanuvchi tugmani bosganida, tost 
yordamida ekranda "Birinchi parcha" xabari ko'rsatiladi. 
package com.abhiandroid.fragmentexample; 
import android.app.Fragment; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.Button; 
import android.widget.Toast; 
 
public class FirstFragment extends Fragment { 


 
 
View view; 
Button firstButton; 
 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
Bundle savedInstanceState) { 
// Inflate the layout for this fragment 
view = inflater.inflate(R.layout.fragment_first, container, false); 
// get the reference of Button 
firstButton = (Button) view.findViewById(R.id.firstButton); 
// perform setOnClickListener on first Button 
firstButton.setOnClickListener(new View.OnClickListener() { 
@Override 
public void onClick(View v) { 

Download 444.29 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10   ...   15




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