Last active
February 20, 2019 23:39
-
-
Save vitorpiovezam/1dd6506863a51fa30946316221f7b17a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.fiap.primeiroaplicativo; | |
import android.support.annotation.NonNull; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.CheckBox; | |
import android.widget.CompoundButton; | |
import android.widget.EditText; | |
import android.widget.RadioButton; | |
import android.widget.RadioGroup; | |
import android.widget.RatingBar; | |
import android.widget.SeekBar; | |
import android.widget.Spinner; | |
import android.widget.Switch; | |
import android.widget.Toast; | |
import android.widget.ToggleButton; | |
public class MainActivity extends AppCompatActivity { | |
private EditText campo1; | |
private EditText campo2; | |
private RatingBar classificador; | |
private SeekBar volume; | |
private CheckBox caixa; | |
private Switch tomada; | |
private ToggleButton ligaDesliga; | |
private RadioGroup grupoDeRadios; | |
private Spinner listaDeDados; | |
private Button botao; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
campo1 = findViewById(R.id.editText); | |
campo2 = findViewById(R.id.editText2); | |
classificador = findViewById(R.id.ratingBar); | |
volume = findViewById(R.id.seekBar); | |
caixa = findViewById(R.id.checkBox); | |
tomada = findViewById(R.id.switch1); | |
ligaDesliga = findViewById(R.id.toggleButton); | |
grupoDeRadios = findViewById(R.id.radioGroup); | |
listaDeDados = findViewById(R.id.spinner); | |
botao = findViewById(R.id.button); | |
caixa.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |
@Override | |
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |
String texto = getString(isChecked); | |
Toast.makeText(MainActivity.this, texto, Toast.LENGTH_SHORT).show(); | |
} | |
@NonNull | |
private String getString(boolean isChecked) { | |
String texto = ""; | |
texto = isChecked ? "Marcado" : "Desmarcado"; | |
return texto; | |
} | |
}); | |
botao.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Toast.makeText(MainActivity.this, | |
"Minha primeira msg. Uhu!", | |
Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
tomada.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |
@Override | |
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |
String texto = ""; | |
texto = isChecked ? "Ligado" : "Desligado"; | |
Toast.makeText(MainActivity.this, | |
texto, | |
Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
grupoDeRadios.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { | |
@Override | |
public void onCheckedChanged(RadioGroup group, int checkedId) { | |
RadioButton radioSelect = findViewById(checkedId); | |
Toast.makeText(MainActivity.this, | |
radioSelect.getText(), | |
Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment