Advertisement
Guest User

MainActivity

a guest
Jan 27th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. public class MainActivity extends FragmentActivity {
  2.  
  3. public static class MyFragment extends Fragment {
  4.  
  5. @Override
  6. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  7. Bundle savedInstanceState) {
  8.  
  9. View view = inflater.inflate(R.layout.fragmentlayout, null);
  10.  
  11. return view;
  12.  
  13. }
  14. }
  15.  
  16. public void myClickMethod(View v) {
  17.  
  18. switch (v.getId()) {
  19. case R.id.button1:
  20. // Logcat
  21. Log.w("MainActivity", "Add Button");
  22. // Toast
  23. Toast.makeText(getApplicationContext(), "Add Button",
  24. Toast.LENGTH_SHORT).show();
  25. }
  26. }
  27.  
  28. FrameLayout container;
  29. FragmentManager fm;
  30. MyFragment mFragment;
  31. String TAG_1 = "FRAGMENT";
  32.  
  33. @Override
  34. protected void onCreate(Bundle savedInstanceState) {
  35. super.onCreate(savedInstanceState);
  36. setContentView(R.layout.activity_main);
  37.  
  38. fm = getSupportFragmentManager();
  39. mFragment = new MyFragment();
  40.  
  41. if (savedInstanceState == null) {
  42.  
  43. FragmentTransaction ft = fm.beginTransaction();
  44. ft.add(R.id.maincontainer, mFragment, TAG_1);
  45. ft.commit();
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement