Manual(mario alberto rosales lara)

Preview:

Citation preview

CECYTEM

Mario Alberto Rosales Lara.

Rene Domínguez Escalona.

Grupo: 403

Aplicaciones Móviles

Desarrollo De Aplicaciones Móviles

RECUPERACION.

INDICE:1.-Hola Mundo

2.-Operaciones

3.-Album

4.-Spinner

5.-RadioButton

6.-ToggleButton

7.-ColorHex

8.- Sonidos

Animales

9.-WebView

10.- CheckBox

11.-Menu

12.-ListView

13.-Acelerometro

14.-Date Picker

15.-VideoView

16.-Acelerometro

17.-Canvas

18.-Gato

19.-Calculadora

20.-IMC

21.-VideoView

22.-Giroscopio

23.-Notificaciones

24.-Factorial

25.-CheckBox

26.-RadioButton

27.-Progress Bar

28.-Spinner

29.-WebView

30.-TimePicker

31.- Giroscopio

“Hola Mundo” Esta aplicación es una de las más básicas de todas ya que es la

primera aplicación que puedes hacer.

Para eso iniciaremos creando nuestro proyecto.

Después lo que tienes que hacer es crear el nombre de tu

Aplicación, Paquete y Proyecto.

Ya creado una vez ponle un icono a tu aplicación.

Despues ponle un nuevo nombre a tu Activity:

Despues ya se habran creado dos ventanillas las cuales uno es el

“.xml” y el otro es el “.java”.

(En el .xml lo que haras es darle diseño a tu pantalla y en el .java ya

va la programacion o lo que hara tu apk).

Para esta primera aplicación solo es para que te des cuenta de

como se crea una aplicación basica.

(no le muevas nada al codigo y ve al apartado de file).

Exportar para instalarlo en tu celular (Export) y quedara asi.

“Operaciones” Con esta aplicación solamente lo que harás será meter dos

números y el programa te dará el resultado de esos números ya

desarrollados por las 4 operaciones básicas que son:

-SUMA.

-RESTA.

-MULTIPLICACION.

-DIVISION.

Iniciaremos creando nuestro proyecto.

Ya creado una vez ponle un icono a tu aplicación

Despues ponle un nombre a tu Activity

Despues ya se habran creado dos ventanillas las cuales uno es el

“.xml” y el otro es el “.java”.

(En el .xml lo que haras es darle diseño a tu pantalla y en el .java ya

va la programacion o lo que hara tu apk).

Despues vas a Res/Layout/activity

Xml:

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/a

ndroid"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#000000"-----------------Color Fondo

android:orientation="vertical" >----------------- Orientacion

(Pantalla)

Despues ingresaremos dos Edit Text para que ingrese los dos

numeros:

<EditText

android:id="@+id/num"

android:layout_width="match_parent"

android:layout_height="50dp"

android:layout_margin="10dp"

android:background="#FFFFFF"

android:hint="numero 1"

android:maxLength="10"

android:numeric="decimal"

android:textColor="#00CC00"

android:textStyle="bold" />

<EditText

android:id="@+id/numd"

android:layout_width="match_parent"

android:layout_height="50dp"

android:layout_margin="10dp"

android:background="#FFFFFF"

android:hint="numero 2"

android:maxLength="10"

android:numeric="decimal"

android:textColor="#00CC00"

android:textStyle="bold" />

Despues se pondra un “LinearLayout” para que se separen nuestros

dos Edit Text

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal" >

Despues del Layout se van a ingresar dos Botones (uno de

Calcular y el otro de Borrar).

<Button

android:id="@+id/cal"

android:layout_width="match_parent"

android:layout_height="50dp"

android:layout_margin="10dp"

android:layout_weight="1"

android:background="#00CC00"

android:text="calcular"

android:textStyle="bold" />

<Button

android:id="@+id/bor"

android:layout_width="match_parent"

android:layout_height="50dp"

android:layout_margin="10dp"

android:layout_weight="1"

android:background="#00CC00"

android:text="borrar"

android:textStyle="bold" />

</LinearLayout>

Despues de ya haber puesto los botones sigue un “TextView” en

donde imprimiran los resultados de los dos numeros ya ingresados

en las operaciones.

<TextView

android:id="@+id/res"

android:layout_width="match_parent"

android:layout_height="102dp"

android:layout_margin="10dp"

android:layout_weight="0.37"

android:background="#FFFFFF"

android:text="resultado"

android:textStyle="bold" />

</LinearLayout>

Y asi quedaria el XML:

Ahora proseguiremos con el (.Java):

Primero se declaran las siguientes librerias:

package aplicacion.operaciones;----------Nombre del paquete

Librerias:

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.*;

import android.app.Activity;

import android.view.Menu;

Despues se agregara el metodo “Onclick Listener” en la clase:

public class Operaciones extends Activity implements OnClickListener{

Despues se declaran las variables:

EditText edtnumerouno, edtnumerodos; --------------- Edit Text

TextView txtresultado; -------------------------- Text View

Button btncalcular, btnborrar; ------------------------- Botones

Despues va el cuerpo, eso ya lo da el proyecto por Default:

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_operaciones);

Despues se decalaran las variables enlazadas con nuestro XML:

edtnumerouno=(EditText) findViewById(R.id.num);

edtnumerodos=(EditText) findViewById(R.id.numd);

txtresultado=(TextView) findViewById(R.id.res);

btncalcular=(Button) findViewById(R.id.cal);

btnborrar=(Button) findViewById(R.id.bor);

Despues se les agrega a los botones el metodo que se declaro

desde el principio en el “.java”.

btncalcular.setOnClickListener(this);

btnborrar.setOnClickListener(this);

}

Despues se agrega el metodo “OnClick”

public void onClick(View v) {

Se crea un caso para la operación

switch(v.getId()){

case R.id.cal:

Se declaran con un “String” los numero con que vas a realizar las

operaciones.

String u=edtnumerouno.getText().toString();

String g=edtnumerodos.getText().toString();

Se crea un cliclo “IF” para cada operacion que quieras realizar.

if(!u.equals("") && !g.equals("")){

double

uno=Double.parseDouble(edtnumerouno.getText().toString());

double

dos=Double.parseDouble(edtnumerodos.getText().toString());

Este “IF” es el que te llevara a la suma total, resta, multiplicacion y

divicion de los numero que ayas introducido al principio.

if(uno<dos){

txtresultado.setText("la suma es: "+(dos+uno)+"\n la resta es:

"+(dos-uno)+"\n la multiplicacion es:"+(dos*uno)+"\n La division es:

"+(dos/uno));

break;

}

}

Se crea un caso del mismo switch que se declaro al principio para

que borre todos los numeros y se quede en blanco.

case R.id.bor:

edtnumerouno.setText("");

edtnumerodos.setText("");

txtresultado.setText("");

break;}

}

}

Y al final esta es nuestra aplicacion terminada.

“Album” Esta aplicacion nos sirve para cambiar el fondo de pantalla.

Para eso iniciaremos creando nuestro proyecto.

Después lo que tienes que hacer es crear el nombre de tu

Aplicación, Paquete y Proyecto.

Ya creado una vez ponle un icono a tu aplicación.

Despues ponle un nuevo nombre a tu Activity:

Despues ya se habran creado dos ventanillas las cuales uno es el

“.xml” y el otro es el “.java”.

(En el .xml lo que haras es darle diseño a tu pantalla y en el .java ya

va la programacion o lo que hara tu apk).

Ya creado tu proyecto te vas a (RES/LAYOUT/Activity_album) en

ese solo dejaras esto:

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/a

ndroid"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

Despues se pone un “ImageView” para que muestre la imagen que

se pondra en el fondo de la pantalla.

<ImageView

android:id="@+id/imagen1"

android:layout_width="match_parent"

android:layout_height="200dp"

android:src="@drawable/a" />

Despues se pone un “HorizontalScrollView” para que las imágenes

los muestre en una lista de forma horizontal.

<HorizontalScrollView

android:layout_width="match_parent"

android:layout_height="100sp" >

Despues se crea otro “LinearLayout” para poder acomodarlos

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal" >

Despues se ponen “9 ImageView” para que sean las imagenes para

ponerlas de fondo, tambien a cada una se le pondra una variable

para que imprima la imagen.

<ImageView

android:id="@+id/imagen2"

android:layout_width="100sp"

android:layout_height="100sp"

android:src="@drawable/b" /> ----------- Variable De la

Imagen

<ImageView

android:id="@+id/imagen3"

android:layout_width="100sp"

android:layout_height="100sp"

android:src="@drawable/c" /> ----------- Variable De

Imagen

<ImageView

android:id="@+id/imagen4"

android:layout_width="100sp"

android:layout_height="100sp"

android:src="@drawable/d" />----------- Variable De

Imagen

<ImageView

android:id="@+id/imagen5"

android:layout_width="100sp"

android:layout_height="100sp"

android:src="@drawable/e" />----------- Variable De

Imagen

<ImageView

android:id="@+id/imagen6"

android:layout_width="100sp"

android:layout_height="100sp"

android:src="@drawable/f" />----------- Variable De

Imagen

<ImageView

android:id="@+id/imagen7"

android:layout_width="100sp"

android:layout_height="100sp"

android:src="@drawable/g" />----------- Variable De

Imagen

<ImageView

android:id="@+id/imagen8"

android:layout_width="100sp"

android:layout_height="100sp"

android:src="@drawable/h" />----------- Variable De

Imagen

<ImageView

android:id="@+id/imagen9"

android:layout_width="100sp"

android:layout_height="100sp"

android:src="@drawable/i" />----------- Variable De

Imagen

<ImageView

android:id="@+id/imagen10"

android:layout_width="100sp"

android:layout_height="100sp"

android:src="@drawable/j" />----------- Variable De

Imagen

Aquí se cierran el “Linear” y el “Horizontal”.

</LinearLayout>

</HorizontalScrollView>

Despues lleva un “Button” y se cierra el “Linear Layout”:

<Button

android:id="@+id/cambiar"

android:layout_width="match_parent"

android:layout_height="70sp"

android:text="Cambiar wallpaper" />------------------ Cambiar

Wallpaper

</LinearLayout>

Despues proceguimos con el JAVA:

Librerias:

import android.os.Bundle;

import android.app.Activity;

import android.app.WallpaperManager;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.*;

Despues implementaremos el metodo OnClickListener:

public class InterfazActivity extends Activity implements

OnClickListener{

Despues Se Declaran Las Variables Que Utilizaremos

ImageView image,image1, image2, image3, image4, image5,

image6, image7, image8, image9,image10;

Button btn;

int fondo;

Despues lleva el cuerpo del programa y el enlazamiento de

nuestras variables y los de XML de las imágenes.

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.interfaz);

image1=(ImageView) findViewById (R.id.imagen1);

image2=(ImageView) findViewById (R.id.imagen2);

image3=(ImageView) findViewById (R.id.imagen3);

image4=(ImageView) findViewById (R.id.imagen4);

image5=(ImageView) findViewById (R.id.imagen5);

image6=(ImageView) findViewById (R.id.imagen6);

image7=(ImageView) findViewById (R.id.imagen7);

image8=(ImageView) findViewById (R.id.imagen8);

image9=(ImageView) findViewById (R.id.imagen9);

btn=(Button) findViewById (R.id.cambiar);

image1.setOnClickListener(this);

image2.setOnClickListener(this);

image3.setOnClickListener(this);

image4.setOnClickListener(this);

image5.setOnClickListener(this);

image6.setOnClickListener(this);

image7.setOnClickListener(this);

image8.setOnClickListener(this);

image9.setOnClickListener(this);

image10.setOnClickListener(this);

btn.setOnClickListener(this);

}

@Override

Despues realizaremos el metodo “OnClick” para las imágenes

poniendolas en casos para que el usuario cuando seleccione una

imagen se ponga el fondo de pantalla.

public void onClick(View v) {

switch (v.getId()){

case R.id.imagen1:

image1.setImageResource(R.drawable.a);

fondo = R.drawable.a;

break;

case R.id.imagen2:

image2.setImageResource(R.drawable.b);

fondo = R.drawable.b;

break;

case R.id.imagen3:

image3.setImageResource(R.drawable.c);

fondo = R.drawable.c;

break;

case R.id.imagen4:

image4.setImageResource(R.drawable.d);

fondo = R.drawable.d;

break;

case R.id.imagen5:

image5.setImageResource(R.drawable.e);

fondo = R.drawable.e;

break;

case R.id.imagen6:

image6.setImageResource(R.drawable.f);

fondo = R.drawable.f;

break;

case R.id.imagen7:

image7.setImageResource(R.drawable.g);

fondo = R.drawable.g;

break;

case R.id.imagen8:

image8.setImageResource(R.drawable.h);

fondo = R.drawable.h;

break;

case R.id.imagen9:

image9.setImageResource(R.drawable.i);

fondo = R.drawable.i;

break;

En este caso lo que mas importa es el permiso para que

pueda hacer el cambio de wallpaper.

case R.id.cambiar:

WallpaperManager

mywp=WallpaperManager.getInstance(getApplicationContext());

try{

mywp.setResource(fondo);

}catch(Exception e){

e.printStackTrace();

}

Toast.makeText(this, "Se a Cambiado el

Wallpaper", Toast.LENGTH_LONG).show();

break;

}}}

Y al final nuestra aplicación queda asi:

“Spinner” Spinner es una aplicación en la cual tu escojes una opcion y de esa

opcion saldran otras.

Para eso iniciaremos creando nuestro proyecto.

Después lo que tienes que hacer es crear el nombre de tu

Aplicación, Paquete y Proyecto.

Ya creado una vez ponle un icono a tu aplicación.

Despues ponle un nuevo nombre a tu Activity:

Despues ya se habran creado dos ventanillas las cuales uno es el

“.xml” y el otro es el “.java”.

(En el .xml lo que haras es darle diseño a tu pantalla y en el .java ya

va la programacion o lo que hara tu apk).

Primero te vas a (RES/LAYOUT/ACTIVITY), despues sigue la

introduccion del “Layout” de como esta tu pantalla.

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#ccc"

android:orientation="vertical"

tools:context=".MainActivity" >

Despues se le pone un “Text View” donde va a ir la primera “Lista

Desplegable”

<TextView

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:gravity="center"

android:text="Selecciona una opcion"

android:textColor="#000"

android:textSize="15sp" />

Despues se declaran los Spinner:

<Spinner

android:id="@+id/sp1"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_margin="10sp"

android:layout_weight="1"

android:textSize="15sp" />

<Spinner

android:id="@+id/sp2"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_margin="10sp"

android:layout_weight="1"

android:textSize="15sp" />

Despues se coloca un “Image View” en donde imprimira una imagen

y se cierra el Layout.

<ImageView

android:id="@+id/image"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_margin="10sp"

android:layout_weight=".7"

android:background="#333" />

</LinearLayout>

Ahora vamos con el JAVA

Primero pondremos las librerias que nos ayudaran a que nuestro

programa corra sin ningun error.

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemSelectedListener;

import android.widget.ArrayAdapter;

import android.widget.ImageView;

import android.widget.Spinner;

Despues sigue la clase del programa y se implementara con el

metodo “ONCLICK”.

public class MainActivity extends Activity implements

OnItemSelectedListener {

Despues se van a declarar las variables que utilizaremos y las

opciones de cada uno de los spinner.

Spinner sp1, sp2;

ImageView img;

ArrayAdapter<String> a, a1, a2, a3, a4, a5;

int sel2 = 0;

String[] opcMarca = new String[] { "VolksWagen", "Ford",

"Nissan", "Honda",

"BMW" };

String[] opcVW = new String[] { "Caribe", "Atlantic", "Golf",

"Jetta",

"Bora" };

String[] opcFord = new String[] { "Mustang", "Fusion", "Fiesta",

"Lobo",

"Ikon" };

String[] opcNissan = new String[] { "NP300", "Sentra", "Altima",

"X-Terra",

"Frontier" };

String[] opcHonda = new String[] { "Civic", "Accord", "CRV",

"Odyssey",

"Pilot" };

String[] opcBMW = new String[] { "Sedan", "Coupe",

"Roadster", "i3", "i8" }

@Override

Despues el cuerpo de nuestro Java que lo da por defauld el mismo

proyecto

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Despues se enlazan los spinner con las variables del XML y las de

“.java”.

sp1 = (Spinner) findViewById(R.id.sp1);

sp2 = (Spinner) findViewById(R.id.sp2);

img = (ImageView) findViewById(R.id.image);

sp1.setOnItemSelectedListener(this);

sp2.setOnItemSelectedListener(this);

a = new ArrayAdapter<String>(this,

android.R.layout.simple_spinner_item, opcMarca);

a1 = new ArrayAdapter<String>(this,

android.R.layout.simple_spinner_item,

opcVW);

a2 = new ArrayAdapter<String>(this,

android.R.layout.simple_spinner_item,

opcFord);

a3 = new ArrayAdapter<String>(this,

android.R.layout.simple_spinner_item,

opcNissan);

a4 = new ArrayAdapter<String>(this,

android.R.layout.simple_spinner_item,

opcHonda);

a5 = new ArrayAdapter<String>(this,

android.R.layout.simple_spinner_item,

opcBMW);

sp1.setAdapter(a);

sp2.setAdapter(a1);

}

@Override

public void onItemSelected(AdapterView<?> arg0, View arg1,

int arg2,

long arg3) {

switch (arg0.getId()) {

case R.id.sp1:

int sel = sp1.getSelectedItemPosition();

switch (sel) {

case 0:

sp2.setAdapter(a1);

sel2 = sp2.getSelectedItemPosition();

switch (sel2) {

case 0:

img.setImageResource(R.drawable.caribe);

break;

case 1:

img.setImageResource(R.drawable.atlantic);

break;

case 2:

img.setImageResource(R.drawable.golf);

break;

case 3:

img.setImageResource(R.drawable.jetta);

break;

case 4:

img.setImageResource(R.drawable.bora);

break;

}

break;

case 1:

sp2.setAdapter(a2);

sel2 = sp2.getSelectedItemPosition();

switch (sel2) {

case 0:

img.setImageResource(R.drawable.mustang);

break;

case 1:

img.setImageResource(R.drawable.fusion);

break;

case 2:

img.setImageResource(R.drawable.fiesta);

break;

case 3:

img.setImageResource(R.drawable.lobo);

break;

case 4:

img.setImageResource(R.drawable.ikon);

break;

}

break;

case 2:

sp2.setAdapter(a3);

sel2 = sp2.getSelectedItemPosition();

switch (sel2) {

case 0:

img.setImageResource(R.drawable.np300);

break;

case 1:

img.setImageResource(R.drawable.sentra);

break;

case 2:

img.setImageResource(R.drawable.altima);

break;

case 3:

img.setImageResource(R.drawable.xterra);

break;

case 4:

img.setImageResource(R.drawable.frontier);

break;

}

break;

case 3:

sp2.setAdapter(a4);

sel2 = sp2.getSelectedItemPosition();

switch (sel2) {

case 0:

img.setImageResource(R.drawable.crv);

break;

case 1:

img.setImageResource(R.drawable.accord);

break;

case 2:

img.setImageResource(R.drawable.crv);

break;

case 3:

img.setImageResource(R.drawable.odysey);

break;

case 4:

img.setImageResource(R.drawable.pilot);

break;

}

break;

case 4:

sp2.setAdapter(a5);

sel2 = sp2.getSelectedItemPosition();

switch (sel2) {

case 0:

img.setImageResource(R.drawable.sedan);

break;

case 1:

img.setImageResource(R.drawable.coupe);

break;

case 2:

img.setImageResource(R.drawable.roadster);

break;

case 3:

img.setImageResource(R.drawable.i3);

break;

case 4:

img.setImageResource(R.drawable.i8);

break;

}

break;

}

break;

}}

@Override

public void onNothingSelected(AdapterView<?> arg0) {

// TODO Auto-generated method stub

}}

Y asi nos queda nuestra aplicación:

“RadioButton” Esta Aplicación es para mostrar cómo nos funciona un radio button

de opción múltiple.

Para eso iniciaremos creando nuestro proyecto.

Después lo que tienes que hacer es crear el nombre de tu

Aplicación, Paquete y Proyecto.

Ya creado una vez ponle un icono a tu aplicación.

Despues ponle un nuevo nombre a tu Activity:

Despues ya se habran creado dos ventanillas las cuales uno es el

“.xml” y el otro es el “.java”.

(En el .xml lo que haras es darle diseño a tu pantalla y en el .java ya

va la programacion o lo que hara tu apk).

Primero Empezaremos Con El XML

<Relative Layout

xmlns:android="http://schemas.android.com/apk/res/androd"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@drawable/sa" >

Después lleva un “TextView” para imprimir los botones de opción en

orden.

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginBottom="10dp"

android:id="@+id/text"

android:text="ChoiceText" />

Después se declara un “Radio Group” para agregar los “Radios

Button” y se declararan 3 radio button (Sound,Vibration y Silent)

como hacer cambio del estado del teléfono.

<RadioGroup

android:id="@+id/myRadioGroup"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/text"

android:layout_marginTop="42dp"

android:background="#abf234"

android:checkedButton="@+id/sound" >

<RadioButton

android:id="@+id/sound"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Sound" />

<RadioButton

android:id="@+id/vibration"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Vibration" />

<RadioButton

android:id="@+id/silent"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Silent" />

</RadioGroup>

Se cierra el “RadioGroup” y se pone un Button que dirá “Choose”

con el que se cambia de opción

<Button

android:id="@+id/chooseBtn"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_marginLeft="34dp"

android:text="Choose" />

Después se cierra el “RelativeLayout” para acabar con el XML

</RelativeLayout>

Después continuaremos con el “.Java” para que funcione el

programa (el paquete).

package practica.radiobutton;

Después se pondrán las librerías necesarias para que funcione el

programa.

import android.os.Bundle;

import android.app.Activity;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.RadioButton;

import android.widget.RadioGroup;

importandroid.widget.RadioGroup.OnCheckedChangeLner;

import android.widget.TextView;

import android.widget.Toast;

Despues se crea la clase en esta situación no llevara el “OnClick”en

la class y se declara el “RadioButton” en la clase .

public class Radiobutton extends Activity {

private RadioGroup radioGroup;

private RadioButton sound, vibration, silent;

private Button button;

private TextView textView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_radiobutton);

Ahora ya una vez declarada la clase del “Radio Button”, se vuelve a

declarar para que tenga una función.

radioGroup=(RadioGroup)findViewById(R.id.myRadioGroup);

radioGroup.setOnCheckedChangeListener(new

OnCheckedChangeListener() {

@Override

Ahora se crean las condiciones para que cuando el usuario

seleccione uno se guarde el cambio.

public void onCheckedChanged(RadioGroup group, int checkedId) {

// find which radio button is selected

if(checkedId == R.id.silent) {

Toast.makeText(getApplicationContext(), "choice:

Silent",

Toast.LENGTH_SHORT).show();

} else if(checkedId == R.id.sound) {

Toast.makeText(getApplicationContext(), "choice:

Sound",

Toast.LENGTH_SHORT).show();

} else {

Toast.makeText(getApplicationContext(), "choice:

Vibration",

Toast.LENGTH_SHORT).show();

}

}

});

sound = (RadioButton) findViewById(R.id.sound);

vibration = (RadioButton)

findViewById(R.id.vibration);

silent = (RadioButton) findViewById(R.id.silent);

textView = (TextView) findViewById(R.id.text);

button = (Button)findViewById(R.id.chooseBtn);

button.setOnClickListener(new OnClickListener() {

@Override

Después aquí es para que imprima un mensaje en cuanto el usuario

presione el “Botón de Choose”.

public void onClick(View v) {

int selectedId =

radioGroup.getCheckedRadioButtonId();

// find which radioButton is checked by id

if(selectedId == sound.getId()) {

textView.setText("You chose

'Sound' option");

} else

if(selectedId == vibration.getId()) {

textView.setText("You chose

'Vibration' option");

} else {

textView.setText("You chose

'Silent' option");

}

}

});

}}

Y así queda nuestro programa ya terminado:

“ToggleButton” Esta aplicación es casi igual que el de “Radio Button”

Para eso iniciaremos creando nuestro proyecto.

Después lo que tienes que hacer es crear el nombre de tu

Aplicación, Paquete y Proyecto.

Ya creado una vez ponle un icono a tu aplicación.

Despues ponle un nuevo nombre a tu Activity:

Despues ya se habran creado dos ventanillas las cuales uno es el

“.xml” y el otro es el “.java”.

(En el .xml lo que haras es darle diseño a tu pantalla y en el .java ya

va la programacion o lo que hara tu apk).

En la parte del XML se declara tanto la orientación, el margen de la

izquierda y de la derecha.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".ToogleButton" > Después se crea un “LinearLayout” para acomodar el “Toggle Button”. <LinearLayout android:id="@+id/fondo" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" android:orientation="horizontal" > Después se pondrá un color en los “Toggle Button” para que cambie cuando el usuario lo seleccione. <ToggleButton android:id="@+id/togglebutton1" android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_margin="5sp" android:textOn="Rojo On" android:textOff="Rojo Off" android:text="ToggleButton" /> <ToggleButton android:id="@+id/togglebutton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5sp" android:textOn="Verde On" android:textOff="Verde Off" android:text="ToggleButton" /> <ToggleButton android:id="@+id/togglebutton3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5sp" android:textOn="Azul On" android:textOff="Azul Off" android:text="ToggleButton" /> </LinearLayout> </LinearLayout> Y se cierra el “XML” Después pasaremos con el “.Java” package mario.tooglebutton; Y se declaran las librerías: import android.os.Bundle; import android.widget.CompoundButton; importandroid.widget.CompoundButton.OnCheckedChangeListene; import android.widget.LinearLayout; import android.widget.ToggleButton; import android.view.Menu; import android.app.Activity;

import android.graphics.Color; Después ya declarada la clase declaremos el método “OnClickListener”. public class ToogleButton extends Activity implements OnCheckedChangeListener { Declaramos las variables que utilizaras para que funcionen nuestras variables. ToggleButton r,v,a; LinearLayout cont; String color="",rj="00",vr="00",az="00"; @Override Se declaran a “r,v,a” que van a ser los “ToggleButton”. protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_toogle_button); cont=(LinearLayout)findViewById(R.id.fondo); r=(ToggleButton)findViewById(R.id.togglebutton1); v=(ToggleButton)findViewById(R.id.togglebutton2); a=(ToggleButton)findViewById(R.id.togglebutton3); En cada “Toggle Button” se le declara el “this” r.setOnCheckedChangeListener(this); v.setOnCheckedChangeListener(this); a.setOnCheckedChangeListener(this); } Después se ponen los casos a cada uno para que cambie de color dependiendo a lo que elija. public void onCheckedChanged(CompoundButton v, boolean isChecked){ switch(v.getId()){ case R.id.togglebutton1: if(isChecked){ rj="FF"; color="#"+rj+vr+az;

cont.setBackgroundColor(Color.parseColor(color)); } else{ rj="00"; color="#"+rj+vr+az; cont.setBackgroundColor(Color.parseColor(color)); } break; case R.id.togglebutton2: if(isChecked){ vr="FF"; color="#"+rj+vr+az; cont.setBackgroundColor(Color.parseColor(color)); } else{ vr="00"; color="#"+rj+vr+az; cont.setBackgroundColor(Color.parseColor(color)); } break; case R.id.togglebutton3: if(isChecked){ az="FF"; color="#"+rj+vr+az; cont.setBackgroundColor(Color.parseColor(color)); }else { az="00"; color="#"+rj+vr+az; cont.setBackgroundColor(Color.parseColor(color)); } break; } }

private ToggleButton setOnCheckedChangeListener(ToogleButton toogleButton) { // TODO Auto-generated method stub return null; } } Y así es como queda nuestra aplicación.

“ColorHexa”

Esta aplicación nos sirve para que te muestre los códigos de

colores que hay, por medio del “Código Hexadecimal”.

Para eso iniciaremos creando nuestro proyecto.

Después lo que tienes que hacer es crear el nombre de tu

Aplicación, Paquete y Proyecto.

Ya creado una vez ponle un icono a tu aplicación.

Despues ponle un nuevo nombre a tu Activity:

Despues ya se habran creado dos ventanillas las cuales uno es el

“.xml” y el otro es el “.java”.

(En el .xml lo que haras es darle diseño a tu pantalla y en el .java ya

va la programacion o lo que hara tu apk).

Empezaremos con el XML que forman las orientaciones y el margen

de nuestra aplicación:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > Después lleva un “LinearLayout” para acomodar los “TextView”. <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > Se ponen en cada “TextView” el nombre de los colores (Rojo, verde y azul). <TextView android:id="@+id/red" android:layout_width="match_parent"

android:layout_height="wrap_content" android:layout_margin="5sp" android:layout_weight="1" android:fontFamily="Arial" android:gravity="center" android:text="Rojo" android:textSize="25sp" /> <TextView android:id="@+id/vrojo " android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5sp" android:layout_weight="1" android:fontFamily="Arial" android:gravity="center" android:text="R:" android:textSize="25sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > Y se declara un “SeekBar” que es para que se pueda mover la barra de los colores. <SeekBar android:id="@+id/rojo" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5sp" android:layout_weight="1" android:gravity="center" android:indeterminate="false" android:max="255" android:progress="1" /> </LinearLayout> Se declara un “LinearLayout” para su orientation: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" >

Se declara otro “Text View” para el siguiente color que va a ser el color verde. <TextView android:id="@+id/green" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5sp" android:layout_weight="1" android:fontFamily="Arial" android:gravity="center" android:text="Verde" android:textSize="25sp" /> <TextView android:id="@+id/vverde" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5sp" android:layout_weight="1" android:fontFamily="Arial" android:gravity="center" android:text="V:" android:textSize="25sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > Se declara un “SeekBar” para el color verde. <SeekBar android:id="@+id/verde" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5sp" android:layout_weight="1" android:gravity="center" android:indeterminate="false" android:max="255" android:progress="1" />

</LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > Se declara el otro color que va a hacer el color azul. <TextView android:id="@+id/blue" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5sp" android:layout_weight="1" android:fontFamily="Arial" android:gravity="center" android:text="Azul" android:textSize="25sp" /> <TextView android:id="@+id/vazul" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5sp" android:layout_weight="1" android:fontFamily="Arial" android:gravity="center" android:text="A:" android:textSize="25sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > Se declara un “SeekBar” para el color. <SeekBar android:id="@+id/azul" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5sp"

android:layout_weight="1" android:gravity="center" android:indeterminate="false" android:max="255" android:progress="1" /> </LinearLayout> Se declaran dos “Text View” que te mostraran un texto que es el color y el Hexadecimal. <TextView android:id="@+id/hex" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5sp" android:fontFamily="Arial" android:gravity="center" android:text="Hexadecimal:" android:textSize="25sp" /> <TextView android:id="@+id/color" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10sp" android:layout_weight="1" android:background="#cccccc" android:fontFamily="Arial" android:gravity="center" android:text="Color" android:textSize="65sp" />

</LinearLayout>

Ahora segiremos con él “.Java”.

package scary.rgb; Después se ponen las Librerías para que corra nuestro programa. import android.os.Bundle; import android.widget.*; import android.app.Activity; Después sigue la clase, creando el method de “SeekBar”:

public class RGB extends Activity implements SeekBar.OnSeekBarChangeListener { Despues se declaran las variables: SeekBar rojo, verde, azul; TextView vrojo, vverde, vazul, hex, color; int r = 0, v = 0, a = 0; Después sigue el cuerpo de la clase. @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_rgb); Después se declaran las variables del color y enlazarlos con los “SeekBarChangeListener”. rojo = (SeekBar) findViewById(R.id.rojo); verde = (SeekBar) findViewById(R.id.verde); azul = (SeekBar) findViewById(R.id.azul); hex = (TextView) findViewById(R.id.hex); vrojo = (TextView) findViewById(R.id.vrojo); vverde = (TextView) findViewById(R.id.vverde); vazul = (TextView) findViewById(R.id.vazul); color = (TextView) findViewById(R.id.color); rojo.setOnSeekBarChangeListener(this); verde.setOnSeekBarChangeListener(this); azul.setOnSeekBarChangeListener(this); } @Override Después sigue un “Public Void” para los casos y cambien a la hora en que se mueva el “SeekBar”. public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { switch (seekBar.getId()) { case R.id.rojo: r = progress; break; case R.id.verde: v = progress;

break; case R.id.azul: a = progress; break; } String c = ColorHex(r, v, a); hex.setText("HEX:" + c); color.setBackgroundColor(android.graphics.Color.rgb(r, v, a)); } Después sigue un “Public String” para que cambien los colores y aparesca el color por “Sexagesimal”. public String ColorHex(int r, int v, int a) { String color = ""; color = "#"; color += Integer.toHexString(r); color += Integer.toHexString(v); color += Integer.toHexString(a); return color; } @Override Después va un método que es el “Tracking Touch” para que agarre con el tacto la combinación de colores. public void onStartTrackingTouch(SeekBar seekBar) { vrojo.setText("R: " + r); vazul.setText("R: " + a); vverde.setText("R: " + v); } @Override public void onStopTrackingTouch(SeekBar seekBar) { vrojo.setText("R: " + r); vazul.setText("R: " + a); vverde.setText("R: " + v); }} Y al final queda nuestra aplicación asi:

“Sonidos De Animales”.

Este nos sirve para reproducir sonidos de animales con cada uno

de los botones.

Para eso iniciaremos creando nuestro proyecto.

Después lo que tienes que hacer es crear el nombre de tu

Aplicación, Paquete y Proyecto.

Ya creado una vez ponle un icono a tu aplicación.

Despues ponle un nuevo nombre a tu Activity:

Despues ya se habran creado dos ventanillas las cuales uno es el

“.xml” y el otro es el “.java”.

(En el .xml lo que haras es darle diseño a tu pantalla y en el .java ya

va la programacion o lo que hara tu apk).

Primero Empezamos con el XML.

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/androi

d"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#ff9966"

android:orientation="vertical"

tools:context=".Grafic" >

Después lleva un “LinearLayout” para acomodar los Botones.

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:orientation="horizontal">

Después lo que tienes que hacer es poner los Botones y poner una

variable para que agarre cada imagen.

<Button

android:id="@+id/uno"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_margin="5sp"

android:layout_weight="1"

android:background="@drawable/auto" />

<Button

android:id="@+id/dos"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:layout_margin="5sp"

android:background="@drawable/avion"/>

<Button

android:id="@+id/tres"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:layout_margin="5sp"

android:background="@drawable/barco"/>

</LinearLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:orientation="horizontal">

<Button

android:id="@+id/cuatro"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:layout_margin="5sp"

android:background="@drawable/bomberos"/>

<Button

android:id="@+id/cinco"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:layout_margin="5sp"

android:background="@drawable/caballo"/>

<Button

android:id="@+id/seis"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:layout_margin="5sp"

android:background="@drawable/camion"/>

</LinearLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:orientation="horizontal">

<Button

android:id="@+id/siete"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:layout_margin="5sp"

android:background="@drawable/policia"/>

<Button

android:id="@+id/ocho"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:layout_margin="5sp"

android:background="@drawable/tren"/>

</LinearLayout>

</LinearLayout>

Después continuaremos con el “Java”.

package scary.sonidos;

Ahora importamos las Librerías para que funcione el programa.

import android.media.AudioManager;

import android.media.SoundPool;

import android.os.Bundle;

import android.app.Activity;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

Después sigue nuestra class.

public class Grafic extends Activity implements OnClickListener {

Ahora vamos a declarar los Botones para el sonido.

SoundPool sp;

Button btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8;

int a1, a2, a3, a4, a5, a6, a7, a8;

Después enlazaremos los Botones con el “XML”.

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_grafic);

btn1 = (Button) findViewById(R.id.uno);

btn2 = (Button) findViewById(R.id.dos);

btn3 = (Button) findViewById(R.id.tres);

btn4 = (Button) findViewById(R.id.cuatro);

btn5 = (Button) findViewById(R.id.cinco);

btn6 = (Button) findViewById(R.id.seis);

btn7 = (Button) findViewById(R.id.siete);

btn8 = (Button) findViewById(R.id.ocho);

btn1.setOnClickListener(this);

btn2.setOnClickListener(this);

btn3.setOnClickListener(this);

btn4.setOnClickListener(this);

btn5.setOnClickListener(this);

btn6.setOnClickListener(this);

btn7.setOnClickListener(this);

btn8.setOnClickListener(this);

Ahora nos vamos a (RES) y creamos una carpeta que se llame

“Raw” e ingresaremos los sonidos en mp3 que llevaran los botones.

sp = new SoundPool(8,

AudioManager.STREAM_MUSIC, 0);

a1 = sp.load(this, R.raw.uno, 1);

a2 = sp.load(this, R.raw.dos, 1);

a3 = sp.load(this, R.raw.tres, 1);

a4 = sp.load(this, R.raw.cuatro, 1);

a5 = sp.load(this, R.raw.cinco, 1);

a6 = sp.load(this, R.raw.seis, 1);

a7 = sp.load(this, R.raw.siete, 1);

a8 = sp.load(this, R.raw.ocho, 1);

}

@Override

Después pondremos los casos dependiendo a los Botones para que

reproduzca sonido por sonido.

public void onClick(View v) {

switch (v.getId()) {

case R.id.uno:

sp.play(a1, 1, 1, 1, 0, 1);

break;

case R.id.dos:

sp.play(a2, 1, 1, 1, 0, 1);

break;

case R.id.tres:

sp.play(a3, 1, 1, 1, 0, 1);

break;

case R.id.cuatro:

sp.play(a4, 1, 1, 1, 0, 1);

break;

case R.id.cinco:

sp.play(a5, 1, 1, 1, 0, 1);

break;

case R.id.seis:

sp.play(a6, 1, 1, 1, 0, 1);

break;

case R.id.siete:

sp.play(a7, 1, 1, 1, 0, 1);

break;

case R.id.ocho:

sp.play(a8, 1, 1, 1, 0, 1);

break;

}

}

}

Y al final queda asi nuestra aplicacion:

“ChekBox” Para eso iniciaremos creando nuestro proyecto.

Después lo que tienes que hacer es crear el nombre de tu

Aplicación, Paquete y Proyecto.

Ya creado una vez ponle un icono a tu aplicación.

Despues ponle un nuevo nombre a tu Activity:

Despues ya se habran creado dos ventanillas las cuales uno es el

“.xml” y el otro es el “.java”.

(En el .xml lo que haras es darle diseño a tu pantalla y en el .java ya

va la programacion o lo que hara tu apk).

Primero Empezaremos Con El XML.

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > Se declaran 2 “Text view” que llevara el titulo y la pregunta para el “Check Box” <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="REDES SOCIALES" android:textColor="#FFFFFF" android:textSize="50sp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10sp"

android:hint="1.¿Cuál es la red social que tiene como icono un pajarito?" android:textColor="#FFFFFF" android:textSize="15sp" /> Se agrega un “Check Box” para indicar la respuesta correcta <CheckBox android:id="@+id/cereala" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="15sp" android:hint="facebook" android:textSize="10sp" /> Ahora pasaremos con el “.JAVA”. Se crea el paquete: package aplicacion.check; Se crean las librerias del Activity: import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.CheckBox; import android.widget.Toast; public class Check extends Activity implements OnClickListener { String message = ""; private CheckBox a, b, c, d, e, f, g, h, i; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_check); Se declaran los “CHECK BOX” en cada una de las respuestas: a = (CheckBox) findViewById(R.id.cereala); b = (CheckBox) findViewById(R.id.cerealb); c = (CheckBox) findViewById(R.id.cerealc);

d = (CheckBox) findViewById(R.id.cereald); e = (CheckBox) findViewById(R.id.cereale); f = (CheckBox) findViewById(R.id.cerealf); g = (CheckBox) findViewById(R.id.cerealg); h = (CheckBox) findViewById(R.id.cerealh); i = (CheckBox) findViewById(R.id.cereali); Se agrega el “this” en cada “CHECK BOX” de la pregunta: a.setOnClickListener(this); b.setOnClickListener(this); c.setOnClickListener(this); d.setOnClickListener(this); e.setOnClickListener(this); f.setOnClickListener(this); g.setOnClickListener(this); h.setOnClickListener(this); i.setOnClickListener(this); } Se crea la clase del “Public void” y se agrega un “switch” para cada caso, dependiendo si esta respuesta es correcta o no es: @Override public void onClick(View arg0) { switch (arg0.getId()) { case R.id.cereala: message = "Tu respuesta es incorrecta"; Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); break; case R.id.cerealb: message = "Tu respuesta es incorrecta"; Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); break; case R.id.cerealc: message = "Tu respuesta es correcta";

Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); break; case R.id.cereald: message = "Tu respuesta es incorrecta"; Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); break; case R.id.cereale: message = "Tu respuesta es incorrecta"; Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); break; case R.id.cerealf: message = "Tu respuesta es correcta"; Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); break; case R.id.cerealg: message = "Tu respuesta es incorrecta"; Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); break; case R.id.cerealh: message = "Tu respuesta es incorrecta"; Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); break; case R.id.cereali: message = "Tu respuesta es correcta";

Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); break; } }

}

Y asi quedara nuestra aplicacion:

“WebView” Para eso iniciaremos creando nuestro proyecto.

Después lo que tienes que hacer es crear el nombre de tu

Aplicación, Paquete y Proyecto.

Ya creado una vez ponle un icono a tu aplicación.

Despues ponle un nuevo nombre a tu Activity:

Despues ya se habran creado dos ventanillas las cuales uno es el

“.xml” y el otro es el “.java”.

(En el .xml lo que haras es darle diseño a tu pantalla y en el .java ya

va la programacion o lo que hara tu apk).

Empezaremos por el “XML”

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > Se declara el “Web View”: <WebView android:id="@+id/webView" android:layout_width="match_parent" android:layout_height="match_parent" /> Se Cierra el XML con el “LINEAR LAYOUT”

</LinearLayout>

Ahora comenzaremos con el “.JAVA”( aqui llevara lo que quieres que tu aplicacion haga) package practica.web; Se crean las librerias para que nuestro programa pueda corer.

import android.app.Activity; import android.os.Bundle; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; Se crea el “public class” public class Web extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_web); Se declara el “Web View” que es el permiso: WebView myWebView = (WebView)this.findViewById (R.id.webView); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); myWebView.setWebViewClient(new WebViewClient()); myWebView.loadUrl("https://www.youtube.com/watch?v=u_0E5Tm5KhU"); }

Y asi queda nuestra aplicacion:

“Menu” Para eso iniciaremos creando nuestro proyecto.

Después lo que tienes que hacer es crear el nombre de tu

Aplicación, Paquete y Proyecto.

Ya creado una vez ponle un icono a tu aplicación.

Despues ponle un nuevo nombre a tu Activity:

Despues ya se habran creado dos ventanillas las cuales uno es el

“.xml” y el otro es el “.java”.

(En el .xml lo que haras es darle diseño a tu pantalla y en el .java ya

va la programacion o lo que hara tu apk).

Empezamos con el “XML”

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FF00FF" > Se agregan los “Text View” que sera nuestro mensaje: <TextView android:id="@+id/mainText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:background="#00FFFF" android:text="Hola" /> </RelativeLayout> Ahora empezaremos con el “.JAVA” package mario.mennu; import android.os.Bundle;

import android.app.Activity;

import android.content.Intent; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; import android.widget.Toast; Se crea la clase del Activity: public class Mennu extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mennu); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.mennu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); String message = "Title:" + item.getTitle() + ", id=" + item.getItemId(); Toast.makeText(this,message, Toast.LENGTH_LONG).show(); Se crea un “Switch” que mostrara que has cambiado el texto. switch(item.getItemId()){ case R.id.mainText: startActivity(new Intent(this, HelpActivity.class)); break; case R.id.action_settings: TextView textView =(TextView)findViewById(R.id.mainText); textView.setText("Cambiaste el Texto :)");

} return true; } }

“ListView” Para eso iniciaremos creando nuestro proyecto.

Después lo que tienes que hacer es crear el nombre de tu

Aplicación, Paquete y Proyecto.

Ya creado una vez ponle un icono a tu aplicación.

Despues ponle un nuevo nombre a tu Activity:

Despues ya se habran creado dos ventanillas las cuales uno es el

“.xml” y el otro es el “.java”.

(En el .xml lo que haras es darle diseño a tu pantalla y en el .java ya

va la programacion o lo que hara tu apk).

Empezaremos con el “XML”

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#f03"> Se agrega un “Linear Layout” para obtener los margenes: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> Se agrega un “Edit Text” para que puedas agregar un elemento. <EditText android:id="@+id/elemento" android:layout_width="match_parent" android:layout_height="fill_parent" android:layout_weight="0.3" android:hint="Agregar Elemento" android:background="#FFFFFF"

android:marqueeRepeatLimit="marquee_forever" android:textSize="25sp" android:textColor="#000000" android:textStyle="bold" /> Se agrega un Boton que al momento de precionarlo te mandara a la lista. <Button android:id="@+id/agregar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="#3f3" android:text="Enter"/> </LinearLayout> <ListView android:id="@+id/lista" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout> Ahora empezaremos con el “.JAVA”(Se crea el paquete): package com.example.hola;

Se crean las librerias que son las basicas. import java.util.ArrayList; import android.os.Bundle; import android.app.Activity; import android.view.View; import android.view.View.OnClickListener; import android.widget.*; Se crea la clase de listado con la implementacion del “OnClickListener”. public class Listado extends Activity implements OnClickListener { EditText elemento; ArrayList<String> elementos; Button btn; ListView lista; ArrayAdapter<String> adaptador;

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list_view); lista = (ListView) findViewById(R.id.lista); elemento = (EditText) findViewById(R.id.elemento); btn = (Button) findViewById(R.id.agregar); elementos = new ArrayList<String>(); adaptador = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, elementos); lista.setAdapter(adaptador); btn.setOnClickListener(this); } @Override public void onClick(View v) { if (v.getId() == R.id.agregar) { elementos.add(elemento.getText().toString()); elemento.setText(""); adaptador.notifyDataSetChanged(); } } }

“Acelerometro” Para eso iniciaremos creando nuestro proyecto.

Después lo que tienes que hacer es crear el nombre de tu

Aplicación, Paquete y Proyecto.

Ya creado una vez ponle un icono a tu aplicación.

Despues ponle un nuevo nombre a tu Activity:

Despues ya se habran creado dos ventanillas las cuales uno es el

“.xml” y el otro es el “.java”.

(En el .xml lo que haras es darle diseño a tu pantalla y en el .java ya

va la programacion o lo que hara tu apk).

Empezamos con el “XML” tanto la orientacion y sus medidas de

vertical y horizontal. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#000000" > Se agrega un “TextView” el cual contendra (/) que sera la pocicion. <TextView android:id="@+id/posisionx" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:layout_margin="10dp" android:textColor="#FFFFFF" android:text="X= "/> Se agrega un “TextView” el cual contendra (Y) que sera la pocicion. <TextView android:id="@+id/posisiony"

android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10dp" android:textColor="#FFFFFF" android:layout_weight="1" android:text="Y= "/> Se agrega un “TextView” el cual contendra (Z) que sera la pocicion. <TextView android:id="@+id/posisionz" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10dp" android:textColor="#FFFFFF" android:text="Z= " android:layout_weight="1"/> Y por ultimo cerramos el “LinearLayout” </LinearLayout>

Ahora comenzaremos con el “.JAVA” package com.cris.acelerometro; Se agregan las librerias que seran los sensores (Sensor, SensorEvent, SensorEventListener, SensorManager). import java.util.List; import android.app.Activity; import android.content.Intent; import android.content.pm.ActivityInfo; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.Bundle; import android.widget.TextView; Se agrega la clase con el implement de SensorEventListener y se declaran las variables que vamos a utilizar.

public class Acelerometro extends Activity implements SensorEventListener { TextView x, y, z; int uno, dos, tres; private Sensor acelerometro; Se agregan las variables (X, Y, Z) que llevaran las pociciones. @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_acelerometro); x = (TextView) findViewById(R.id.posisionx); y = (TextView) findViewById(R.id.posisiony); z = (TextView) findViewById(R.id.posisionz); this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } protected void onResume() { super.onResume(); SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE); List<Sensor> sensors = sm.getSensorList(Sensor.TYPE_ACCELEROMETER); Se crea un ciclo de “if” que nos indicara cuando toquemos cada uno de los sensores. if (sensors.size() > 0) { sm.registerListener(this, sensors.get(0), SensorManager.SENSOR_DELAY_GAME); } } protected void onPause() { SensorManager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mSensorManager.unregisterListener(this, acelerometro); super.onPause(); }

protected void onStop() { SensorManager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mSensorManager.unregisterListener(this, acelerometro); super.onStop(); } En este public llevara el sensor cuando se mueva (En los puntos X, Y & Z). @Override public void onSensorChanged(SensorEvent event) { this.x.setText("X = " + event.values[SensorManager.DATA_X]); this.y.setText("Y = " + event.values[SensorManager.DATA_Y]); this.z.setText("Z = " + event.values[SensorManager.DATA_Z]); float xx = event.values[SensorManager.DATA_X]; float yy = event.values[SensorManager.DATA_Y]; float zz = event.values[SensorManager.DATA_Z]; if (xx >= 9.6) { Intent edad= new Intent(Acelerometro.this,edad.class); startActivity(edad); } if (yy >= 9.6) { Intent mundo= new Intent(Acelerometro.this,Mundo.class); startActivity(mundo); } if (zz >= 9.6) { Intent operaciones= new Intent(Acelerometro.this,operaciones.class); startActivity(operaciones); } } @Override public void onAccuracyChanged(Sensor arg0, int arg1) {

// TODO Auto-generated method stub } } Y asi queda nuestra aplicación:

“Calculadora” Para eso iniciaremos creando nuestro proyecto.

Después lo que tienes que hacer es crear el nombre de tu

Aplicación, Paquete y Proyecto.

Ya creado una vez ponle un icono a tu aplicación.

Despues ponle un nuevo nombre a tu Activity:

Despues ya se habran creado dos ventanillas las cuales uno es el

“.xml” y el otro es el “.java”.

(En el .xml lo que haras es darle diseño a tu pantalla y en el .java ya

va la programacion o lo que hara tu apk).

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000" android:orientation="vertical" tools:context=".Calculadors" > <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10sp" android:layout_weight="1" android:id="@+id/cifras" android:background="#ffffff" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" >

<TextView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10sp" android:id="@+id/resultado" android:layout_weight="1" android:background="#ffffff" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" > <Button android:id="@+id/boruno" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#ff0000" android:text="DEL" android:onClick="delete" android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> <Button android:id="@+id/bortodo" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#ff0000" android:text="AC" android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> </LinearLayout> </LinearLayout>

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" > <Button android:id="@+id/siete" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#999999" android:text="7" android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> <Button android:id="@+id/ocho" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#999999" android:text="8" android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> <Button android:id="@+id/nueve" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#999999" android:text="9" android:textColor="#fff" android:textSize="30sp" android:textStyle="bold"

android:typeface="serif" /> <Button android:id="@+id/div" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#0066ff" android:text="/" android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" > <Button android:id="@+id/cuatro" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#999999" android:text="4" android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> <Button android:id="@+id/cinco" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#999999" android:text="5"

android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> <Button android:id="@+id/seis" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#999999" android:text="6" android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> <Button android:id="@+id/mul" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#0066ff" android:text="*" android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" > <Button android:id="@+id/uno" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp"

android:layout_weight="1" android:background="#999999" android:text="1" android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> <Button android:id="@+id/dos" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#999999" android:text="2" android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> <Button android:id="@+id/tres" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#999999" android:text="3" android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> <Button android:id="@+id/res" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#0066ff" android:text="-" android:textColor="#fff"

android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" > <Button android:id="@+id/punto" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#999999" android:text="." android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> <Button android:id="@+id/cero" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#999999" android:text="0" android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> <Button android:id="@+id/igual" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1"

android:background="#33cc00" android:text="=" android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> <Button android:id="@+id/mas" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:background="#0066ff" android:text="+" android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" android:typeface="serif" /> </LinearLayout>

</LinearLayout>

package scary.calculadors; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class Calculadors extends Activity implements OnClickListener { Button btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btnsuma, btnresta, btnmult, btndiv, btnigual, btndel, btnac, btnpunto; TextView txtcifras, txtResultado; float num1 = 0, num2 = 0, resultado = 0; int o = 0;

boolean p = false, igual = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_calculadors); txtcifras = (TextView) findViewById(R.id.cifras); txtResultado = (TextView) findViewById(R.id.resultado); btn1 = (Button) findViewById(R.id.uno); btn2 = (Button) findViewById(R.id.dos); btn3 = (Button) findViewById(R.id.tres); btn4 = (Button) findViewById(R.id.cuatro); btn5 = (Button) findViewById(R.id.cinco); btn6 = (Button) findViewById(R.id.seis); btn7 = (Button) findViewById(R.id.siete); btn8 = (Button) findViewById(R.id.ocho); btn9 = (Button) findViewById(R.id.nueve); btn0 = (Button) findViewById(R.id.cero); btnpunto = (Button) findViewById(R.id.punto); btnsuma = (Button) findViewById(R.id.mas); btnresta = (Button) findViewById(R.id.res); btnmult = (Button) findViewById(R.id.mul); btndiv = (Button) findViewById(R.id.div); btndel = (Button) findViewById(R.id.bortodo); btnac = (Button) findViewById(R.id.boruno); btnigual = (Button) findViewById(R.id.igual); btn1.setOnClickListener(this); btn2.setOnClickListener(this); btn3.setOnClickListener(this); btn4.setOnClickListener(this); btn5.setOnClickListener(this); btn6.setOnClickListener(this); btn7.setOnClickListener(this); btn8.setOnClickListener(this); btn9.setOnClickListener(this); btn0.setOnClickListener(this); btnpunto.setOnClickListener(this); btnsuma.setOnClickListener(this); btnresta.setOnClickListener(this); btnmult.setOnClickListener(this); btndiv.setOnClickListener(this); btnigual.setOnClickListener(this); btndel.setOnClickListener(this);

btnac.setOnClickListener(this); } public void deshabilitar() { btnsuma.setEnabled(false); btnresta.setEnabled(false); btnmult.setEnabled(false); btndiv.setEnabled(false); } public void habilitar() { btnsuma.setEnabled(true); btnresta.setEnabled(true); btnmult.setEnabled(true); btndiv.setEnabled(true); } public boolean validar() { if (txtResultado.getText().equals("")) { Toast.makeText(this, "Falta introducir Numero ", Toast.LENGTH_SHORT) .show(); return false; } else { if (o == 0) { num1 = Float.parseFloat(txtcifras.getText().toString()); } else { num2 = Float.parseFloat(txtcifras.getText().toString()); } return true; } } public void borrar() { txtcifras.setText(""); txtResultado.setText(""); resultado = 0; num1 = 0; num2 = 0; }

@Override public void onClick(View v) { switch (v.getId()) { case R.id.mas: if (validar() == true) { if (igual == true) { resultado = num1; igual = false; } else { resultado = 0; } txtResultado.setText(num1 + "+"); txtcifras.setText(""); o = 3; p = false; deshabilitar(); } break; case R.id.res: if (validar() == true) { if (igual == true) { resultado = num1; igual = false; } else { resultado = 0; } txtResultado.setText(num1 + "-"); txtcifras.setText(""); o = 4; p = false; deshabilitar(); } break; case R.id.mul: if (validar() == true) { if (igual == true) { resultado = num1; igual = false; } else { resultado = 0; } txtResultado.setText(num1 + "*"); txtcifras.setText("");

o = 5; p = false; deshabilitar(); } break; case R.id.div: if (validar() == true) { if (igual == true) { resultado = num1; igual = false; } else { resultado = 0; } txtResultado.setText(num1 + "/"); txtcifras.setText(""); o = 6; p = false; deshabilitar(); } break; case R.id.uno: if (igual == true) { borrar(); igual = false; } txtResultado.append("1"); break; case R.id.dos: if (igual == true) { borrar(); igual = false; } txtResultado.append("2"); break; case R.id.tres: if (igual == true) { borrar(); igual = false; } txtResultado.append("3"); break; case R.id.cuatro:

if (igual == true) { borrar(); igual = false; } txtResultado.append("4"); break; case R.id.cinco: if (igual == true) { borrar(); igual = false; } txtResultado.append("5"); break; case R.id.seis: if (igual == true) { borrar(); igual = false; } txtResultado.append("6"); break; case R.id.siete: if (igual == true) { borrar(); igual = false; } txtResultado.append("7"); break; case R.id.ocho: if (igual == true) { borrar(); igual = false; } txtResultado.append("8"); break; case R.id.nueve: if (igual == true) { borrar(); igual = false; } txtResultado.append("9"); break; case R.id.cero: if (igual == true) {

borrar(); igual = false; } txtResultado.append("0"); break; case R.id.punto: if (p == false && igual == false) { txtcifras.append("."); p = true; } else { if (p == false) { if (resultado != 0) { borrar(); } txtcifras.append("."); p = true; igual = false; } } break; case R.id.boruno: String cad = txtcifras.getText().toString(); if (!cad.equals("")) { char[] cadena = cad.toCharArray(); String f = ""; for (int i = 0; i <= cadena.length - 2; i++) { f = f + cadena[i]; } txtcifras.setText(f); } else { Toast.makeText(this, "No hay valor", Toast.LENGTH_SHORT).show(); resultado = 0; habilitar(); } break; case R.id.bortodo: borrar(); habilitar(); break; case R.id.igual: if (validar() == true) { switch (o) {

case 3: resultado = num1 + num2; break; case 4: resultado = num1 - num2; break; case 5: resultado = num1 * num2; break; case 6: resultado = num1 / num2; break; } } o = 0; p = false; num1 = resultado; igual = true; habilitar(); txtResultado.append("" + num2); txtcifras.setText("" + redondear(resultado)); break; } } /*TheScary*/// public float redondear(float numero) { return (float) Math.rint(numero * 100000) / 100000; }

} Y asi queda nuestra aplicacion:

“Giroscopio” Para eso iniciaremos creando nuestro proyecto.

Después lo que tienes que hacer es crear el nombre de tu

Aplicación, Paquete y Proyecto.

Ya creado una vez ponle un icono a tu aplicación.

Despues ponle un nuevo nombre a tu Activity:

Despues ya se habran creado dos ventanillas las cuales uno es el

“.xml” y el otro es el “.java”.

(En el .xml lo que haras es darle diseño a tu pantalla y en el .java ya

va la programacion o lo que hara tu apk).

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#3366ff" android:orientation="vertical" tools:context=".MainActivity" > <LinearLayout

android:layout_width="match_parent" android:layout_height="50sp" android:orientation="horizontal" > <TextView android:id="@+id/xid" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:text="TextView" /> <TextView android:id="@+id/yid" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:text="TextView" /> <TextView android:id="@+id/zid" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5sp" android:layout_weight="1" android:text="TextView" /> </LinearLayout>

</LinearLayout>

package scary.giro; import java.util.List;

import android.app.Activity; import android.content.pm.ActivityInfo; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends Activity implements SensorEventListener { TextView x, y, z; private Sensor mAccelerometr; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main ); x = (TextView) findViewById(R.id.xid); y = (TextView) findViewById(R.id.yid); z = (TextView) findViewById(R.id.zid); this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } protected void onResume() { super.onResume(); SensorManager sm=(SensorManager)getSystemService(SENSOR_SERVICE); List<Sensor> sensors=sm.getSensorList(Sensor.TYPE_ACCELEROMETER); if(sensors.size()>0){ sm.registerListener(this,sensors.get(0),SensorManager.SENSOR_DELAY_GAME); } } protected void onPause() {

SensorManager mSensorManager=(SensorManager)getSystemService(SENSOR_SERVICE); mSensorManager.unregisterListener(this,mAccelerometr); super.onPause(); } protected void onStop() { SensorManager mSensorManager=(SensorManager)getSystemService(SENSOR_SERVICE); mSensorManager.unregisterListener(this,mAccelerometr); super.onStop(); } Aqui llevara el Sensor de magnetismo que dara los puntos (X, Y, Z) @Override public void onSensorChanged(SensorEvent event) { this.x.setText("X = "+event.values[SensorManager.DATA_X]); this.y.setText("Y = "+event.values[SensorManager.DATA_Y]); this.z.setText("Z = "+event.values[SensorManager.DATA_Z]); } @Override public void onAccuracyChanged(Sensor arg0, int arg1) { // TODO Auto-generated method stub } }

Y asi queda nuestra aplicación:

Recommended