Advertisement
MarMar_IV

SettingsForm_Fragment

Jun 7th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.93 KB | None | 0 0
  1. package cz.kpb.mmw;
  2.  
  3.  
  4. import android.os.Bundle;
  5. import android.support.v4.app.Fragment;
  6. import android.support.v4.app.FragmentActivity;
  7. import android.support.v4.app.FragmentManager;
  8. import android.support.v4.app.FragmentTransaction;
  9. import android.view.LayoutInflater;
  10. import android.view.Menu;
  11. import android.view.MenuItem;
  12. import android.view.View;
  13. import android.view.ViewGroup;
  14. import android.widget.Button;
  15.  
  16. public class SettingsForm extends FragmentActivity {
  17.  
  18.     @Override
  19.     protected void onCreate(Bundle savedInstanceState) {
  20.         super.onCreate(savedInstanceState);
  21.         setContentView(R.layout.activity_settings_form);
  22.  
  23.         if (savedInstanceState == null) {
  24.             //FragmentManager fragmentManager = getFragmentManager();
  25.             FragmentManager fragmentManager = getSupportFragmentManager();
  26.             FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
  27.             SettingFragment_Page1 fragment = new SettingFragment_Page1();
  28.             fragmentTransaction.add(R.id.container, fragment, "tag");
  29.             fragmentTransaction.commit();
  30.             fragmentManager.executePendingTransactions();
  31.  
  32.             SettingFragment_Page1 fra = (SettingFragment_Page1) getSupportFragmentManager().findFragmentByTag("tag");
  33.  
  34.             fra.SetText("aaaa");
  35.             //Log.d("I: ", fra.GetText());
  36.         }
  37.     }
  38.  
  39.  
  40.     @Override
  41.     public boolean onCreateOptionsMenu(Menu menu) {
  42.        
  43.         // Inflate the menu; this adds items to the action bar if it is present.
  44.         getMenuInflater().inflate(R.menu.settings_form, menu);
  45.         return true;
  46.     }
  47.  
  48.     @Override
  49.     public boolean onOptionsItemSelected(MenuItem item) {
  50.         // Handle action bar item clicks here. The action bar will
  51.         // automatically handle clicks on the Home/Up button, so long
  52.         // as you specify a parent activity in AndroidManifest.xml.
  53.         int id = item.getItemId();
  54.         if (id == R.id.action_settings) {
  55.             return true;
  56.         }
  57.         return super.onOptionsItemSelected(item);
  58.     }
  59.  
  60.  
  61.  
  62.     /**
  63.      * A SettingFragment fragment containing a simple view.
  64.      */
  65.     public static class SettingFragment_Page1 extends Fragment {
  66.         View rootView;
  67.  
  68.         private Button mButton1;
  69.  
  70.         public SettingFragment_Page1() {
  71.         }
  72.  
  73.         @Override
  74.         public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  75.             rootView = inflater.inflate(R.layout.fragment_settings_form_page1, container, false);
  76.  
  77.             mButton1 = (Button) rootView.findViewById(R.id.button);
  78.  
  79.             return rootView;
  80.         }
  81.  
  82.         public void SetText(String aa){
  83.             mButton1 = (Button) rootView.findViewById(R.id.button);
  84.             mButton1.setText(aa);
  85.         }
  86.  
  87.         public String GetText(){
  88.             return Double.toString(Math.random());
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement