am_dot_com

DDM 2022-10-18

Oct 18th, 2022 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:orientation="vertical"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent">
  7.  
  8. <!-- botões CSE e CSD
  9. a propriedade gravity controla o posicionamento do conteúdo
  10. de um elemento no elemento
  11. -->
  12. <LinearLayout
  13. android:gravity="top"
  14. android:layout_weight="1"
  15. android:orientation="horizontal"
  16. android:layout_width="match_parent"
  17. android:layout_height="wrap_content"
  18. >
  19. <!-- haverá conteúdo aqui (os 2 botões) -->
  20. <!-- Button são elementos vazios de conteúdo -->
  21. <!-- Não devemos usar onClick
  22. MAS, se usarmos, daremos o nome de um método que tem
  23. que ser implementado na Activity que venha a carregar
  24. este Layout. E terá que respeitar uma assinatura muito
  25. precisa. -->
  26. <Button
  27. android:layout_weight="1"
  28. android:id="@+id/idBtnCSE"
  29. android:onClick="responderAoClick"
  30. android:text="@string/strBtnCSE"
  31. android:layout_width="wrap_content"
  32. android:layout_height="wrap_content"/>
  33.  
  34. <Button
  35. android:layout_weight="1"
  36. android:id="@+id/idBtnCSD"
  37. android:text="@string/strBtnCSD"
  38. android:layout_width="wrap_content"
  39. android:layout_height="wrap_content"/>
  40.  
  41. </LinearLayout>
  42.  
  43. <!-- botões CIE e CID -->
  44.  
  45. <LinearLayout
  46. android:layout_weight="1"
  47. android:orientation="horizontal"
  48. android:layout_width="match_parent"
  49. android:layout_height="wrap_content">
  50.  
  51. <Button
  52. android:id="@+id/idBtnCIE"
  53. android:layout_gravity="bottom"
  54. android:layout_weight="1"
  55. android:text="@string/strBtnCIE"
  56. android:layout_width="match_parent"
  57. android:layout_height="wrap_content"/>
  58.  
  59. <Button
  60. android:id="@+id/idBtnCID"
  61. android:layout_gravity="bottom"
  62. android:layout_weight="1"
  63. android:text="@string/strBtnCID"
  64. android:layout_width="match_parent"
  65. android:layout_height="wrap_content"/>
  66. </LinearLayout>
  67. </LinearLayout>
  68.  
  69. ****************************************
  70.  
  71. package com.joythis.android.fourcorners;
  72.  
  73. import androidx.appcompat.app.AppCompatActivity;
  74.  
  75. import android.content.Context;
  76. import android.os.Bundle;
  77. import android.util.Log;
  78. import android.view.Gravity;
  79. import android.view.View;
  80. import android.widget.Button;
  81. import android.widget.Toast;
  82.  
  83. public class MainActivity extends AppCompatActivity {
  84. public final static String STAMP = "@MainActivity";
  85.  
  86. /*
  87. Todos os elementos de layout que sejam relevantes para a
  88. programação (para comportamento) têm que ter um id no Layout
  89. e devem ter um data member correspondente na class da Activity
  90. que carregar o Layout
  91. */
  92. Button mBtnCSE;
  93. Button mBtnCSD;
  94. Button mBtnCIE;
  95. Button mBtnCID;
  96.  
  97. Context mContext;
  98.  
  99. @Override
  100. protected void onCreate(Bundle savedInstanceState) {
  101. super.onCreate(savedInstanceState);
  102. // setContentView(R.layout.activity_main);
  103. setContentView(R.layout.rl_four_corners_v1);
  104.  
  105. init();
  106. } // onCreate
  107.  
  108. void init(){
  109. // inicializações dos data members
  110. mContext = this;
  111. mBtnCSE = findViewById(R.id.idBtnCSE);
  112. mBtnCSD = findViewById(R.id.idBtnCSD);
  113. mBtnCIE = findViewById(R.id.idBtnCIE);
  114. mBtnCID = findViewById(R.id.idBtnCID);
  115.  
  116. // controlo de qualidade
  117. Object[] theRelevant = {
  118. mContext,
  119. mBtnCSE,
  120. mBtnCSD,
  121. mBtnCIE,
  122. mBtnCID
  123. };
  124. boolean bFoundANull = false;
  125. for (Object r : theRelevant){
  126. bFoundANull = r==null;
  127. if (bFoundANull){
  128. // mensagem
  129. Log.e(
  130. STAMP,
  131. "There is 1+ null relevant objects. Aborting."
  132. );
  133. this.finish();
  134. return;
  135. }
  136. } // for
  137.  
  138. // conferir comportamentos
  139.  
  140. } // init
  141.  
  142. public void responderAoClick(View pV){
  143. Toast t = Toast.makeText(
  144. this,
  145. getResources().getString(R.string.strBtnCSE),
  146. Toast.LENGTH_SHORT
  147. );
  148. t.setGravity(
  149. Gravity.CENTER,
  150. 0,
  151. 0
  152. );
  153. t.show();
  154. } // responderAoClick
  155. } // class MainActivity
Advertisement
Add Comment
Please, Sign In to add comment