Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <!-- botões CSE e CSD
- a propriedade gravity controla o posicionamento do conteúdo
- de um elemento no elemento
- -->
- <LinearLayout
- android:gravity="top"
- android:layout_weight="1"
- android:orientation="horizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- >
- <!-- haverá conteúdo aqui (os 2 botões) -->
- <!-- Button são elementos vazios de conteúdo -->
- <!-- Não devemos usar onClick
- MAS, se usarmos, daremos o nome de um método que tem
- que ser implementado na Activity que venha a carregar
- este Layout. E terá que respeitar uma assinatura muito
- precisa. -->
- <Button
- android:layout_weight="1"
- android:id="@+id/idBtnCSE"
- android:onClick="responderAoClick"
- android:text="@string/strBtnCSE"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
- <Button
- android:layout_weight="1"
- android:id="@+id/idBtnCSD"
- android:text="@string/strBtnCSD"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
- </LinearLayout>
- <!-- botões CIE e CID -->
- <LinearLayout
- android:layout_weight="1"
- android:orientation="horizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <Button
- android:id="@+id/idBtnCIE"
- android:layout_gravity="bottom"
- android:layout_weight="1"
- android:text="@string/strBtnCIE"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"/>
- <Button
- android:id="@+id/idBtnCID"
- android:layout_gravity="bottom"
- android:layout_weight="1"
- android:text="@string/strBtnCID"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"/>
- </LinearLayout>
- </LinearLayout>
- ****************************************
- package com.joythis.android.fourcorners;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.Context;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.Gravity;
- import android.view.View;
- import android.widget.Button;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- public final static String STAMP = "@MainActivity";
- /*
- Todos os elementos de layout que sejam relevantes para a
- programação (para comportamento) têm que ter um id no Layout
- e devem ter um data member correspondente na class da Activity
- que carregar o Layout
- */
- Button mBtnCSE;
- Button mBtnCSD;
- Button mBtnCIE;
- Button mBtnCID;
- Context mContext;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // setContentView(R.layout.activity_main);
- setContentView(R.layout.rl_four_corners_v1);
- init();
- } // onCreate
- void init(){
- // inicializações dos data members
- mContext = this;
- mBtnCSE = findViewById(R.id.idBtnCSE);
- mBtnCSD = findViewById(R.id.idBtnCSD);
- mBtnCIE = findViewById(R.id.idBtnCIE);
- mBtnCID = findViewById(R.id.idBtnCID);
- // controlo de qualidade
- Object[] theRelevant = {
- mContext,
- mBtnCSE,
- mBtnCSD,
- mBtnCIE,
- mBtnCID
- };
- boolean bFoundANull = false;
- for (Object r : theRelevant){
- bFoundANull = r==null;
- if (bFoundANull){
- // mensagem
- Log.e(
- STAMP,
- "There is 1+ null relevant objects. Aborting."
- );
- this.finish();
- return;
- }
- } // for
- // conferir comportamentos
- } // init
- public void responderAoClick(View pV){
- Toast t = Toast.makeText(
- this,
- getResources().getString(R.string.strBtnCSE),
- Toast.LENGTH_SHORT
- );
- t.setGravity(
- Gravity.CENTER,
- 0,
- 0
- );
- t.show();
- } // responderAoClick
- } // class MainActivity
Advertisement
Add Comment
Please, Sign In to add comment