SlideShare a Scribd company logo
//mainxml
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
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:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/f1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fragment1" />
<Button
android:id="@+id/f2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fragment2" />
<FrameLayout
android:id="@+id/framlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
//mainjava
package com.example.notification;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;
import android.app.Fragment;
import android.annotation.SuppressLint;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.List;
public class MainActivity extends AppCompatActivity {
Button btn1;
Button btn2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1=(Button)findViewById(R.id.f1);
btn2=(Button)findViewById(R.id.f2);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadfragment(new Fragment1());
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadfragment(new Fagmment2());
}
});
}
public void loadfragment(Fragment fragment) {
FragmentManager fm =getFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
ft.replace(R.id.framlayout, fragment);
ft.commit();
}
}
//frgmnt1javaclasss
package com.example.notification;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.app.Fragment;
import java.util.zip.Inflater;
public class Fragment1 extends Fragment {
View v;
Button b1;
@Override
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
v=inflater.inflate(R.layout.f1,container,false);
b1=(Button)v.findViewById(R.id.f1btn);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity(),"yes this click on 1st
fragment",Toast.LENGTH_LONG).show();
}
});
return v;
}
}
//frgmnt2
package com.example.notification;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import android.app.Fragment;
public class Fagmment2 extends Fragment {
View v;
Button b2;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
v=inflater.inflate(R.layout.f2,container,false);
b2=(Button)v.findViewById(R.id.f2btn);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity(),"yes this click on 2nd
fragment",Toast.LENGTH_LONG).show();
}
});
return v;
}
}
//f1layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="30sp"
android:layout_marginTop="40sp"
android:text="my 1st" />
<Button
android:id="@+id/f1btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="160sp"
android:layout_marginTop="200sp"
android:text="First Fragment" />
</androidx.appcompat.widget.LinearLayoutCompat>
//f2layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="30sp"
android:layout_marginTop="40sp"
android:text="my 2nd fragment" />
<Button
android:id="@+id/f2btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="160sp"
android:layout_marginTop="200sp"
android:text="2nd fragment" />
</androidx.appcompat.widget.LinearLayoutCompat>

More Related Content

What's hot

Lab 9 list view
Lab 9 list viewLab 9 list view
Lab 9 list view
Phonepaseuth Phonhdala
 
Actividad 11
Actividad 11Actividad 11
Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016
Yuki Anzai
 
Aula 10 04 (Gerenciadores de layouts)
Aula 10 04 (Gerenciadores de layouts)Aula 10 04 (Gerenciadores de layouts)
Aula 10 04 (Gerenciadores de layouts)
Ricardo Longa
 
Activity accueil
Activity accueilActivity accueil
Activity accueil
Saber LAJILI
 
Main.xml
Main.xmlMain.xml
Main.xml
Saber LAJILI
 
Programa6
Programa6Programa6
Programa6
josuedelangel
 
Quick tips for android
Quick tips for androidQuick tips for android
Quick tips for android
Daniel Baccin
 
Fragment demo
Fragment demoFragment demo
Fragment demo
Krishna Kant
 
Material Design with Support Design Library
Material Design with Support Design LibraryMaterial Design with Support Design Library
Material Design with Support Design Library
Taeho Kim
 
Actividad 02
Actividad 02Actividad 02
Actividad 02
Jose AC
 
20101106 연합세미나 Session 2
20101106 연합세미나 Session 220101106 연합세미나 Session 2
20101106 연합세미나 Session 2
Hyeon Cheol Pak
 
Portafolio
PortafolioPortafolio
Portafolio
marioorozco2g
 
Latihan android
Latihan androidLatihan android
Latihan android
tasmin amin
 
Client server part 8
Client server part 8Client server part 8
Client server part 8
fadlihulopi
 
Part 4
Part 4Part 4
Part 4
fadlihulopi
 

What's hot (16)

Lab 9 list view
Lab 9 list viewLab 9 list view
Lab 9 list view
 
Actividad 11
Actividad 11Actividad 11
Actividad 11
 
Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016
 
Aula 10 04 (Gerenciadores de layouts)
Aula 10 04 (Gerenciadores de layouts)Aula 10 04 (Gerenciadores de layouts)
Aula 10 04 (Gerenciadores de layouts)
 
Activity accueil
Activity accueilActivity accueil
Activity accueil
 
Main.xml
Main.xmlMain.xml
Main.xml
 
Programa6
Programa6Programa6
Programa6
 
Quick tips for android
Quick tips for androidQuick tips for android
Quick tips for android
 
Fragment demo
Fragment demoFragment demo
Fragment demo
 
Material Design with Support Design Library
Material Design with Support Design LibraryMaterial Design with Support Design Library
Material Design with Support Design Library
 
Actividad 02
Actividad 02Actividad 02
Actividad 02
 
20101106 연합세미나 Session 2
20101106 연합세미나 Session 220101106 연합세미나 Session 2
20101106 연합세미나 Session 2
 
Portafolio
PortafolioPortafolio
Portafolio
 
Latihan android
Latihan androidLatihan android
Latihan android
 
Client server part 8
Client server part 8Client server part 8
Client server part 8
 
Part 4
Part 4Part 4
Part 4
 

More from university of Gujrat, pakistan

Change management
Change management Change management
Change management
university of Gujrat, pakistan
 
Latest Trends in Digital Marketing
Latest Trends in Digital MarketingLatest Trends in Digital Marketing
Latest Trends in Digital Marketing
university of Gujrat, pakistan
 
Dark web (2)
Dark web (2)Dark web (2)
Code of ethics and professional conduct (1)
Code of ethics and professional conduct (1)Code of ethics and professional conduct (1)
Code of ethics and professional conduct (1)
university of Gujrat, pakistan
 
Certification accreditation and licensure (1)
Certification accreditation and licensure (1)Certification accreditation and licensure (1)
Certification accreditation and licensure (1)
university of Gujrat, pakistan
 
biggest technology trends
biggest technology trendsbiggest technology trends
biggest technology trends
university of Gujrat, pakistan
 
Freedom of information (1)
Freedom of information (1)Freedom of information (1)
Freedom of information (1)
university of Gujrat, pakistan
 
Individual cognition ppt (1)
Individual cognition ppt (1)Individual cognition ppt (1)
Individual cognition ppt (1)
university of Gujrat, pakistan
 
Top 10 highest (1)
Top 10 highest (1)Top 10 highest (1)
Top 10 highest (1)
university of Gujrat, pakistan
 
creativity and imagination
creativity and imagination creativity and imagination
creativity and imagination
university of Gujrat, pakistan
 
Brainstorming 078 (1)
Brainstorming 078 (1)Brainstorming 078 (1)
Brainstorming 078 (1)
university of Gujrat, pakistan
 
speeh-artificial intelligemce
speeh-artificial intelligemce speeh-artificial intelligemce
speeh-artificial intelligemce
university of Gujrat, pakistan
 
Pp dealing with problem complexity (1)
Pp dealing with problem complexity (1)Pp dealing with problem complexity (1)
Pp dealing with problem complexity (1)
university of Gujrat, pakistan
 
Motivation
MotivationMotivation
Vision of artificial intelligence (1)
Vision of artificial intelligence (1)Vision of artificial intelligence (1)
Vision of artificial intelligence (1)
university of Gujrat, pakistan
 
Entrepreneurship (1)
Entrepreneurship (1)Entrepreneurship (1)
Entrepreneurship (1)
university of Gujrat, pakistan
 
Role of professional societies
Role of professional societiesRole of professional societies
Role of professional societies
university of Gujrat, pakistan
 
Dealing with culticultural environment (1)
Dealing with culticultural environment (1)Dealing with culticultural environment (1)
Dealing with culticultural environment (1)
university of Gujrat, pakistan
 
Dealing with problem complexity (1)
Dealing with problem complexity (1)Dealing with problem complexity (1)
Dealing with problem complexity (1)
university of Gujrat, pakistan
 
cyber security and cyber crime
cyber security and cyber crime cyber security and cyber crime
cyber security and cyber crime
university of Gujrat, pakistan
 

More from university of Gujrat, pakistan (20)

Change management
Change management Change management
Change management
 
Latest Trends in Digital Marketing
Latest Trends in Digital MarketingLatest Trends in Digital Marketing
Latest Trends in Digital Marketing
 
Dark web (2)
Dark web (2)Dark web (2)
Dark web (2)
 
Code of ethics and professional conduct (1)
Code of ethics and professional conduct (1)Code of ethics and professional conduct (1)
Code of ethics and professional conduct (1)
 
Certification accreditation and licensure (1)
Certification accreditation and licensure (1)Certification accreditation and licensure (1)
Certification accreditation and licensure (1)
 
biggest technology trends
biggest technology trendsbiggest technology trends
biggest technology trends
 
Freedom of information (1)
Freedom of information (1)Freedom of information (1)
Freedom of information (1)
 
Individual cognition ppt (1)
Individual cognition ppt (1)Individual cognition ppt (1)
Individual cognition ppt (1)
 
Top 10 highest (1)
Top 10 highest (1)Top 10 highest (1)
Top 10 highest (1)
 
creativity and imagination
creativity and imagination creativity and imagination
creativity and imagination
 
Brainstorming 078 (1)
Brainstorming 078 (1)Brainstorming 078 (1)
Brainstorming 078 (1)
 
speeh-artificial intelligemce
speeh-artificial intelligemce speeh-artificial intelligemce
speeh-artificial intelligemce
 
Pp dealing with problem complexity (1)
Pp dealing with problem complexity (1)Pp dealing with problem complexity (1)
Pp dealing with problem complexity (1)
 
Motivation
MotivationMotivation
Motivation
 
Vision of artificial intelligence (1)
Vision of artificial intelligence (1)Vision of artificial intelligence (1)
Vision of artificial intelligence (1)
 
Entrepreneurship (1)
Entrepreneurship (1)Entrepreneurship (1)
Entrepreneurship (1)
 
Role of professional societies
Role of professional societiesRole of professional societies
Role of professional societies
 
Dealing with culticultural environment (1)
Dealing with culticultural environment (1)Dealing with culticultural environment (1)
Dealing with culticultural environment (1)
 
Dealing with problem complexity (1)
Dealing with problem complexity (1)Dealing with problem complexity (1)
Dealing with problem complexity (1)
 
cyber security and cyber crime
cyber security and cyber crime cyber security and cyber crime
cyber security and cyber crime
 

Fragmentwithouttag

  • 1. //mainxml <?xml version="1.0" encoding="utf-8"?> <androidx.appcompat.widget.LinearLayoutCompat 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:orientation="vertical" tools:context=".MainActivity"> <Button android:id="@+id/f1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Fragment1" /> <Button android:id="@+id/f2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Fragment2" /> <FrameLayout android:id="@+id/framlayout" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout> </androidx.appcompat.widget.LinearLayoutCompat> //mainjava package com.example.notification; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.NotificationCompat; import android.app.Fragment; import android.annotation.SuppressLint; import android.app.FragmentManager; import android.app.FragmentTransaction; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.os.Build; import android.os.Bundle;
  • 2. import android.view.View; import android.widget.Button; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.List; public class MainActivity extends AppCompatActivity { Button btn1; Button btn2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn1=(Button)findViewById(R.id.f1); btn2=(Button)findViewById(R.id.f2); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { loadfragment(new Fragment1()); } }); btn2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { loadfragment(new Fagmment2()); } }); } public void loadfragment(Fragment fragment) { FragmentManager fm =getFragmentManager(); FragmentTransaction ft=fm.beginTransaction(); ft.replace(R.id.framlayout, fragment); ft.commit(); } } //frgmnt1javaclasss package com.example.notification; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.Toast;
  • 3. import androidx.annotation.NonNull; import androidx.annotation.Nullable; import android.app.Fragment; import java.util.zip.Inflater; public class Fragment1 extends Fragment { View v; Button b1; @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { v=inflater.inflate(R.layout.f1,container,false); b1=(Button)v.findViewById(R.id.f1btn); b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getActivity(),"yes this click on 1st fragment",Toast.LENGTH_LONG).show(); } }); return v; } } //frgmnt2 package com.example.notification; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.Toast; import android.app.Fragment; public class Fagmment2 extends Fragment { View v; Button b2; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { v=inflater.inflate(R.layout.f2,container,false); b2=(Button)v.findViewById(R.id.f2btn); b2.setOnClickListener(new View.OnClickListener() { @Override
  • 4. public void onClick(View v) { Toast.makeText(getActivity(),"yes this click on 2nd fragment",Toast.LENGTH_LONG).show(); } }); return v; } } //f1layout <?xml version="1.0" encoding="utf-8"?> <androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="30sp" android:layout_marginTop="40sp" android:text="my 1st" /> <Button android:id="@+id/f1btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="160sp" android:layout_marginTop="200sp" android:text="First Fragment" /> </androidx.appcompat.widget.LinearLayoutCompat> //f2layout <?xml version="1.0" encoding="utf-8"?> <androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"
  • 5. > <TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="30sp" android:layout_marginTop="40sp" android:text="my 2nd fragment" /> <Button android:id="@+id/f2btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="160sp" android:layout_marginTop="200sp" android:text="2nd fragment" /> </androidx.appcompat.widget.LinearLayoutCompat>