Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:orientation="vertical"
  8. android:gravity="center"
  9. tools:context=".MainActivity">
  10.  
  11. <EditText
  12. android:layout_width="310dp"
  13. android:layout_height="70dp"
  14. android:hint="Enter Your Name"
  15. android:textColorHint="@color/colorPrimaryDark"
  16. android:id="@+id/name"
  17. android:textColor="@color/colorPrimaryDark"
  18. android:textSize="30dp"/>
  19.  
  20. <Button
  21. android:id="@+id/btn"
  22. android:layout_marginTop="20dp"
  23. android:textColor="#fff"
  24. android:textSize="30dp"
  25. android:background="@color/colorPrimaryDark"
  26. android:text=" Click Here "
  27. android:layout_width="wrap_content"
  28. android:layout_height="wrap_content" />
  29.  
  30. <TextView
  31. android:id="@+id/result"
  32. android:text="Your name is ?"
  33. android:layout_marginTop="30dp"
  34. android:textColor="@color/colorAccent"
  35. android:textSize="30dp"
  36. android:layout_width="wrap_content"
  37. android:layout_height="wrap_content" />
  38.  
  39. </LinearLayout>
  40.  
  41.  
  42.  
  43.  
  44.  
  45. package com.example.administrator.class2;
  46.  
  47. import android.support.v7.app.AppCompatActivity;
  48. import android.os.Bundle;
  49. import android.view.View;
  50. import android.widget.Button;
  51. import android.widget.EditText;
  52. import android.widget.TextView;
  53.  
  54. public class MainActivity extends AppCompatActivity {
  55.  
  56. EditText name;
  57. Button btn;
  58. TextView result;
  59.  
  60. @Override
  61. protected void onCreate(Bundle savedInstanceState) {
  62. super.onCreate(savedInstanceState);
  63. setContentView(R.layout.activity_main);
  64.  
  65. name = (EditText) findViewById(R.id.name);
  66. btn = (Button) findViewById(R.id.btn);
  67. result = (TextView) findViewById(R.id.result);
  68.  
  69. btn.setOnClickListener(new View.OnClickListener() {
  70. @Override
  71. public void onClick(View v) {
  72. result.setText("Your name is " + name.getText().toString());
  73. }
  74. });
  75.  
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement