Logo Studenta

Practica-24-09-22 - Osvaldo Campos

¡Este material tiene más páginas!

Vista previa del material en texto

Programación web
Tema 2 “Practica 24-09-22”
Nombre del (la) estudiante: Olivia Vazquez Mora b223z1003, Osvaldo Rincón Campos 193z0223
Huatusco, Ver., 26 de Septiembre de 2022
PROGRAMA 1 (VIDEO)
CODIGO ACTIVITY MAIN (XML)
	<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".MainActivity">
 <Spinner
 android:id="@+id/spnimagenes"
 android:layout_width="409dp"
 android:layout_height="wrap_content"
 android:layout_marginStart="1dp"
 android:layout_marginLeft="1dp"
 android:layout_marginTop="4dp"
 android:entries="@array/imagenes"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent" />
 <ImageView
 android:id="@+id/imgFoto"
 android:layout_width="354dp"
 android:layout_height="377dp"
 app:layout_constraintBottom_toBottomOf="parent"
 app:layout_constraintEnd_toEndOf="parent"
 app:layout_constraintHorizontal_bias="0.491"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent"
 app:layout_constraintVertical_bias="0.675"
 app:srcCompat="@drawable/ic_launcher_background" />
 <RadioGroup
 android:id="@+id/radioGroup"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginStart="204dp"
 android:layout_marginLeft="204dp"
 android:layout_marginTop="128dp"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent">
 </RadioGroup>
 <RadioButton
 android:id="@+id/rbtimagen1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_marginTop="92dp"
 android:onClick="cambiarImagenRBT"
 android:text="RadioButton"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent" />
 <RadioButton
 android:id="@+id/rbtimagen2"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_marginTop="64dp"
 android:onClick="cambiarImagenRBT"
 android:text="RadioButton"
 app:layout_constraintEnd_toEndOf="parent"
 app:layout_constraintHorizontal_bias="1.0"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent" />
 <RadioButton
 android:id="@+id/rbtimagen3"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_marginTop="140dp"
 android:onClick="cambiarImagenRBT"
 android:text="RadioButton"
 app:layout_constraintEnd_toEndOf="parent"
 app:layout_constraintHorizontal_bias="0.0"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent" />
 <CheckBox
 android:id="@+id/chkimagen1"
 android:layout_width="124dp"
 android:layout_height="45dp"
 android:layout_marginStart="232dp"
 android:layout_marginLeft="232dp"
 android:layout_marginTop="64dp"
 android:onClick="cambiarImagenCheck"
 android:text="@string/rbtimagen1"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent" />
 <CheckBox
 android:id="@+id/chkimagen2"
 android:layout_width="123dp"
 android:layout_height="38dp"
 android:layout_marginStart="232dp"
 android:layout_marginLeft="232dp"
 android:layout_marginTop="112dp"
 android:onClick="cambiarImagenCheck"
 android:text="@string/rbtimagen2"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent" />
 <CheckBox
 android:id="@+id/chkimagen3"
 android:layout_width="122dp"
 android:layout_height="42dp"
 android:layout_marginStart="232dp"
 android:layout_marginLeft="232dp"
 android:layout_marginTop="148dp"
 android:onClick="cambiarImagenCheck"
 android:text="@string/rbtimagen3"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
CODIGO MAIN ACTIVITY (JAVA)
	package com.example.controlesseleccion;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.Spinner;
public class MainActivity extends AppCompatActivity {
 Spinner spnImagenes;
 ImageView imgFoto;
 CheckBox check;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 spnImagenes=findViewById(R.id.spnimagenes);
 imgFoto=findViewById(R.id.imgFoto);
 spnImagenes.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
 @Override
 public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
 switch(i){
 case 0:
 imgFoto.setImageResource(R.drawable.ic_launcher_background);
 break;
 case 1:
 imgFoto.setImageResource(R.drawable.imagen1);
 break;
 case 2:
 imgFoto.setImageResource(R.drawable.image2);
 break;
 case 3:
 imgFoto.setImageResource(R.drawable.imagen3);
 break;
 }
 }
 @Override
 public void onNothingSelected(AdapterView<?> adapterView) {
 }
 });
 }
 public void cambiarImagenRBT(View view){
 switch(view.getId()){
 case R.id.rbtimagen1:
 imgFoto.setImageResource(R.drawable.imagen1);
 break;
 case R.id.rbtimagen2:
 imgFoto.setImageResource(R.drawable.image2);
 break;
 case R.id.rbtimagen3:
 imgFoto.setImageResource(R.drawable.imagen3);
 break;
 }
 }
 public void cambiarImagenCheck(View view){
 switch(view.getId()){
 case R.id.chkimagen1:
 check=findViewById(R.id.chkimagen1);
 if(check.isChecked()){
 imgFoto.setImageResource(R.drawable.imagen1);
 } else {
 imgFoto.setImageResource(R.drawable.ic_launcher_background);
 }
 break;
 case R.id.chkimagen2:
 check=findViewById(R.id.chkimagen2);
 if(check.isChecked()){
 imgFoto.setImageResource(R.drawable.image2);
 } else {
 imgFoto.setImageResource(R.drawable.ic_launcher_background);
 }
 break;
 case R.id.chkimagen3:
 check=findViewById(R.id.chkimagen3);
 if(check.isChecked()){
 imgFoto.setImageResource(R.drawable.imagen3);
 } else {
 imgFoto.setImageResource(R.drawable.ic_launcher_background);
 }
 break;
 }
 }
}
CODIGO STRING (XML)
	<resources>
 <string name="app_name">ControlesSeleccion</string>
 <string name="rbtimagen1">Imagen 1</string>
 <string name="rbtimagen2">Imagen 2</string>
 <string name="rbtimagen3">Imagen 3</string><string-array name="imagenes">
 <item>"Selecciona una opcion"</item>
 <item>"Imagen 1"</item>
 <item>"Imagen 2"</item>
 <item>"Imagen 3"</item>
 </string-array>
</resources>
PROGRAMA 2 (CALCULADORA CON RADIO BUTTON)
.
.
.
.
CODIGO ACTIVITY MAIN (XML)
	<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".MainActivity">
 <EditText
 android:id="@+id/dato1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginStart="192dp"
 android:layout_marginLeft="192dp"
 android:layout_marginTop="16dp"
 android:ems="10"
 android:inputType="textPersonName"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent" />
 <EditText
 android:id="@+id/dato2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginStart="192dp"
 android:layout_marginLeft="192dp"
 android:layout_marginTop="84dp"
 android:ems="10"
 android:inputType="textPersonName"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent" />
 <TextView
 android:id="@+id/res1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginStart="160dp"
 android:layout_marginLeft="160dp"
 android:layout_marginTop="620dp"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent" />
 <RadioGroup
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginStart="180dp"
 android:layout_marginLeft="180dp"
 android:layout_marginTop="212dp"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent" >
 <RadioButton
 android:id="@+id/sum1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:onClick="operaciones"
 android:text="Suma"
 tools:text="@string/sum1" />
 <RadioButton
 android:id="@+id/sub1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:onClick="operaciones"
 android:text="Resta"
 tools:text="@string/sub1" />
 <RadioButton
 android:id="@+id/div1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:onClick="operaciones"
 android:text="División"
 tools:text="@string/div1" />
 <RadioButton
 android:id="@+id/mul1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:onClick="operaciones"
 android:text="Multiplicación"
 tools:text="@string/mul1" />
 </RadioGroup>
 <TextView
 android:id="@+id/textView6"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginStart="132dp"
 android:layout_marginLeft="132dp"
 android:layout_marginTop="40dp"
 android:text="Valor 1"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent" />
 <TextView
 android:id="@+id/textView7"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginStart="132dp"
 android:layout_marginLeft="132dp"
 android:layout_marginTop="100dp"
 android:text="Valor 2"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
CODIGO MAIN ACTIVITY (JAVA)
	package com.example.calc;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
 TextView resultado;
 EditText d1,d2;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 d1=(EditText)findViewById(R.id.dato1);
 d2=(EditText)findViewById(R.id.dato2);
 resultado=(TextView)findViewById(R.id.res1);
 }
 public void operaciones(View view){
 float d11,d22,subt11;
 String resul11;
 switch(view.getId()){
 case R.id.sum1:
 d11=0;
 d22=0;
 subt11=0;
 d11=Float.parseFloat(d1.getText().toString());
 d22=Float.parseFloat(d2.getText().toString());
 subt11=d11+d22;
 resul11=String.valueOf(subt11);
 resultado.setText(resul11);
 break;
 case R.id.sub1:
 d11=0;
 d22=0;
 subt11=0;
 d11=Float.parseFloat(d1.getText().toString());
 d22=Float.parseFloat(d2.getText().toString());
 subt11=d11-d22;
 resul11=String.valueOf(subt11);
 resultado.setText(resul11);
 break;
 case R.id.mul1:
 d11=0;
 d22=0;
 subt11=0;
 d11=Float.parseFloat(d1.getText().toString());
 d22=Float.parseFloat(d2.getText().toString());
 subt11=d11*d22;
 resul11=String.valueOf(subt11);
 resultado.setText(resul11);
 break;
 case R.id.div1:
 d11=0;
 d22=0;
 subt11=0;
 d11=Float.parseFloat(d1.getText().toString());
 d22=Float.parseFloat(d2.getText().toString());
 subt11=d11/d22;
 resul11=String.valueOf(subt11);
 resultado.setText(resul11);
 break;
 }
 }
}
Página | 19

Continuar navegando