0% found this document useful (0 votes)
5 views2 pages

Fragment

Uploaded by

paalsahil04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Fragment

Uploaded by

paalsahil04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

--------------------------------------------------------------------

package com.example.imt_69;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

public class newsFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_news,container,false);
Button add = view.findViewById(R.id.add);
TextView n1= view.findViewById(R.id.num1);
TextView n2=view.findViewById(R.id.num2);

add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int number1 , number2,ans;
number1=Integer.parseInt(n1.getText().toString());
number2=Integer.parseInt(n2.getText().toString());

ans= number1+number2;
Intent intent = new Intent(getActivity(),MainActivity2.class);
intent.putExtra("ans",ans);
startActivity(intent);
}
});

return view;

}
}

-----------------------------------------------------------------------------------
----------
sci1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getSupportFragmentManager();

fragmentManager.beginTransaction().replace(R.id.fragmentContainerView,sciFragment.c
lass, null)
.setReorderingAllowed(true).addToBackStack("NAME").commit()
;

}
});
}
}

You might also like