Advertisement
MarMar_IV

SettingsForm

Jun 6th, 2014
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.96 KB | None | 0 0
  1. package cz.kpb.mmw;
  2.  
  3. import android.app.Fragment;
  4. import android.app.FragmentManager;
  5. import android.app.FragmentTransaction;
  6. import android.os.Bundle;
  7. import android.support.v4.app.FragmentActivity;
  8. import android.util.Log;
  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.  
  17. public class SettingsForm extends FragmentActivity implements View.OnClickListener{
  18.  
  19.     @Override
  20.     protected void onCreate(Bundle savedInstanceState) {
  21.         super.onCreate(savedInstanceState);
  22.         setContentView(R.layout.activity_settings_form);
  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.  
  31.  
  32.             SettingFragment_Page1 fra = (SettingFragment_Page1) getFragmentManager().findFragmentByTag("tag");
  33.  
  34.             fra.setButtonText("aaaa");
  35.             Log.d("I: ", fra.getButtonText());
  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.     @Override
  61.     public void onClick(View v) {
  62.         Functions.ShowMessage(Integer.toString(v.getId()),this);
  63.     }
  64.  
  65.  
  66.     /**
  67.      * A SettingFragment fragment containing a simple view.
  68.      */
  69.     public static class SettingFragment_Page1 extends Fragment{
  70.         private Button mButton1;
  71.  
  72.         public SettingFragment_Page1() {
  73.         }
  74.  
  75.         @Override
  76.         public View onCreateView(LayoutInflater inflater, ViewGroup container,
  77.                 Bundle savedInstanceState) {
  78.             View rootView = inflater.inflate(R.layout.fragment_settings_form_page1, container, false);
  79.  
  80.             mButton1 = (Button) rootView.findViewById(R.id.button);
  81.  
  82.             return rootView;
  83.         }
  84.  
  85.         public void setButtonText(String text){
  86.             mButton1.setText(text);
  87.         }
  88.  
  89.         public String getButtonText(){
  90.             return mButton1.getText().toString();
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement