Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. package com.example.testen;
  2.  
  3. import android.os.Bundle;
  4.  
  5.  
  6. public class MainActivity extends ActionBarActivity {
  7. TextView tv;
  8. Button b1;
  9. @Override
  10. protected void onCreate(Bundle savedInstanceState) {
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.activity_main);
  13. b1 = (Button)findViewById(R.id.button1);
  14. tv = (TextView)findViewById(R.id.textView1);
  15. b1.setOnClickListener(new View.OnClickListener() {
  16.  
  17. @Override
  18. public void onClick(View v) {
  19. // TODO Auto-generated method stub
  20. tv.setText("hello");
  21. }
  22. });
  23.  
  24. if (savedInstanceState == null) {
  25. getSupportFragmentManager().beginTransaction()
  26. .add(R.id.container, new PlaceholderFragment())
  27. .commit();
  28. }
  29. }
  30.  
  31.  
  32. @Override
  33. public boolean onCreateOptionsMenu(Menu menu) {
  34.  
  35. // Inflate the menu; this adds items to the action bar if it is present.
  36. getMenuInflater().inflate(R.menu.main, menu);
  37. return true;
  38. }
  39.  
  40. @Override
  41. public boolean onOptionsItemSelected(MenuItem item) {
  42. // Handle action bar item clicks here. The action bar will
  43. // automatically handle clicks on the Home/Up button, so long
  44. // as you specify a parent activity in AndroidManifest.xml.
  45. int id = item.getItemId();
  46. if (id == R.id.action_settings) {
  47. return true;
  48. }
  49. return super.onOptionsItemSelected(item);
  50. }
  51.  
  52. /**
  53. * A placeholder fragment containing a simple view.
  54. */
  55. public static class PlaceholderFragment extends Fragment {
  56.  
  57. public PlaceholderFragment() {
  58. }
  59.  
  60. @Override
  61. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  62. Bundle savedInstanceState) {
  63. View rootView = inflater.inflate(R.layout.fragment_main, container, false);
  64. return rootView;
  65. }
  66. }
  67.  
  68. }
  69.  
  70. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  71. xmlns:tools="http://schemas.android.com/tools"
  72. android:layout_width="match_parent"
  73. android:layout_height="match_parent"
  74. android:paddingBottom="@dimen/activity_vertical_margin"
  75. android:paddingLeft="@dimen/activity_horizontal_margin"
  76. android:paddingRight="@dimen/activity_horizontal_margin"
  77. android:paddingTop="@dimen/activity_vertical_margin"
  78. tools:context="com.example.testen.MainActivity$PlaceholderFragment" >
  79.  
  80. <TextView
  81. android:id="@+id/textView1"
  82. android:layout_width="wrap_content"
  83. android:layout_height="wrap_content"
  84. android:text="@string/hello_world" />
  85.  
  86. <Button
  87. android:id="@+id/button1"
  88. android:layout_width="wrap_content"
  89. android:layout_height="wrap_content"
  90. android:layout_below="@+id/textView1"
  91. android:layout_marginTop="62dp"
  92. android:text="Button" />
  93.  
  94. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement