Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainFragment extends Fragment {
- private static final int REQUEST_CODE_DETAILS_ACTIVITY = 1234;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- return inflater.inflate(R.layout.fragment_main, container, false);
- //return inflater.inflate(R.layout.fragment_screen2, container, false);
- }
- @Override
- public void onActivityCreated(Bundle savedState) {
- super.onActivityCreated(savedState);
- Button b1 = (Button) getActivity().findViewById(R.id.button1);
- b1.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- onClickMethod(R.id.button1);
- }
- });
- // Button b2 = (Button) getActivity().findViewById((R.id.button2);
- //b2.setOnClickListener(new View.);
- }
- public void onClickMethod(int id) {
- // int id = R.id.button1;
- Toast.makeText(getActivity(), "does the id get passed?" +id , Toast.LENGTH_SHORT).show();
- if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
- int testint = 323;
- FragScreen2 frag = (com.example.engg6600.fragtest2.FragScreen2) getFragmentManager().findFragmentById(R.id.fragment_screen2);
- //frag.changeText(id);
- try {
- ((FragScreen2)getFragmentManager().findFragmentById(R.id.fs2)).testMethod(testint);
- } catch (Exception e) {
- Toast.makeText(getActivity(), "breaks" + testint, Toast.LENGTH_SHORT).show();
- }
- //Intent goS2 = new Intent(getActivity(), Screen2.class);
- //goS2.putExtra("buttonNumber", id);
- // FragScreen2 frag = (FragScreen2) getFragmentManager().findFragmentById(R.id.fragment_screen2);
- // Toast.makeText(getActivity(), "before to frag.changetext(id)", Toast.LENGTH_LONG).show();
- // frag.changeText(id);
- // Toast.makeText(getActivity(), "sent to frag.changetext(id)", Toast.LENGTH_LONG).show();
- } else{
- // String toastString = Integer.toString(id);
- Toast.makeText(getActivity(), "portrait mode id" +id, Toast.LENGTH_LONG).show();
- Intent goS2 = new Intent(getActivity(), Screen2.class);
- goS2.putExtra("buttonNumber", id);
- startActivityForResult(goS2, REQUEST_CODE_DETAILS_ACTIVITY);
- }
- }
- }
- public class FragScreen2 extends Fragment {
- private static final String[] SCREENTEXT ={
- "You have selected button 1",
- "You have selected button 2",
- "You have selected button 3",
- "You have selected button 4",
- "No selection"
- };
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- return inflater.inflate(R.layout.fragment_screen2, container, false);
- }
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- // pull out the country ID to show from the activity's intent
- Intent intent = getActivity().getIntent();
- int id = intent.getIntExtra("buttonNumber", 234324);
- Toast.makeText(getActivity(), "fragscreen 2 id=" +id, Toast.LENGTH_LONG).show();
- changeText(id);
- }
- public void changeText(int id) {
- int buttonNumber=4;
- Toast.makeText(getActivity(), "button1 of R.id" + Integer.toString(R.id.button1), Toast.LENGTH_SHORT).show();
- if (id==R.id.button1) {
- buttonNumber =0;
- } else if (id==R.id.button2) {
- buttonNumber =1;
- } else if (id==R.id.button3) {
- buttonNumber =2;
- } else if (id==R.id.button4) {
- buttonNumber =3;
- }
- String text = SCREENTEXT[buttonNumber];
- TextView tv = (TextView)getActivity().findViewById(R.id.textscreen2);
- tv.setText(text);
- }
- public void testMethod (int integerVar) {
- Toast.makeText(getActivity(), "testmethod int=" + integerVar, Toast.LENGTH_SHORT).show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement