Laboratoriya ishi №16 Mavzu: Voqealar (intents)


// display a message by using a Toast


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

// display a message by using a Toast 
Toast.makeText(getActivity(), 
"First 
Fragment", 
Toast.LENGTH_LONG).show(); 

}); 
return view; 


SecondFragment.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 "Ikkinchi fragment" 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 SecondFragment extends Fragment { 
 


View view; 
Button secondButton; 
 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
Bundle savedInstanceState) { 
// Inflate the layout for this fragment 
view = inflater.inflate(R.layout.fragment_second, container, false); 
// get the reference of Button 
secondButton = (Button) view.findViewById(R.id.secondButton); 
// perform setOnClickListener on second Button 
secondButton.setOnClickListener(new View.OnClickListener() { 
@Override 
public void onClick(View v) { 
// display a message by using a Toast 
Toast.makeText(getActivity(), 
"Second 
Fragment", 
Toast.LENGTH_LONG).show(); 

Download 444.29 Kb.

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




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