Usuario:ManuelRomero/Android/PrimerContacto/nav
package com.example.pruebaventanadialogo;
import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.AlertDialog.Builder; import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.view.Gravity; import android.view.Menu; import android.view.View; import android.widget.Toast;
public class Dialogo extends Activity { //En android es más comun usar CharSequence que String. CharSequence[] idiomas={"Españlo","Inglés","Alemán"}; CharSequence[] sexo={"Hombre","Mujer","Prefiero no contestar"};
boolean [] idiomasSeleccionados=new boolean[idiomas.length];
ProgressDialog barraSofisticadaDialogo;
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialogo); }
@SuppressWarnings("deprecation") public void clickMesajeOpciones(View v) { showDialog(0); } public void clickSexo(View v) { showDialog(1); } public void clickProgressDialog(View v){ final ProgressDialog barraProgreso = ProgressDialog.show(this, "Haciendo algo","Espere que termine",true); new Thread(new Runnable(){ public void run(){ try{ Thread.sleep(5000); barraProgreso.dismiss(); }catch (InterruptedException e){ e.printStackTrace(); } } }).start();
} public void clickProgressDialog2(View v){ showDialog(2); barraSofisticadaDialogo.setProgress(0); new Thread(new Runnable(){ public void run(){ for (int i=1;i<=15;i++){ try{ Thread.sleep(100); barraSofisticadaDialogo.incrementProgressBy((int)(100/15));
}catch (InterruptedException e){ e.printStackTrace(); } }//End for barraSofisticadaDialogo.dismiss(); } }).start();
}
public void clickToast(View v){
/*Toast toast = Toast.makeText(getApplicationContext(), "Ejemplo de Mensaje Popup para Android OS desde Devtroce.com", Toast.LENGTH_SHORT); toast.show(); */ Context contesto = getApplicationContext(); CharSequence texto = "Este ejemplo ha funcionado FACIL!!!!"; int duracion = Toast.LENGTH_SHORT; Toast mensaje = Toast.makeText(contesto, texto, duracion); mensaje.show(); } @Override protected Dialog onCreateDialog(int id){ switch (id){ case 0: Builder ventanaDialogo = new AlertDialog.Builder(this); ventanaDialogo.setIcon(R.drawable.ic_launcher); ventanaDialogo.setTitle("Ejemplo de cuadro diálogo 1 con texto" ); ventanaDialogo.setPositiveButton("SI", new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Context contesto = getBaseContext(); int duracion=Toast.LENGTH_SHORT; Toast.makeText(contesto,"OK seleccionado",duracion).show(); } });
ventanaDialogo.setNegativeButton("NOOO", new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Context contesto = getBaseContext(); int duracion=Toast.LENGTH_SHORT; Toast.makeText(contesto,"NOOOOOO seleccionado",duracion).show(); } });
ventanaDialogo.setMultiChoiceItems(idiomas,idiomasSeleccionados, new DialogInterface.OnMultiChoiceClickListener() {
@Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { // TODO Auto-generated method stub Context contesto = getBaseContext(); int duracion=Toast.LENGTH_SHORT; Toast.makeText(contesto,idiomas[which]+(isChecked ? "seleccionado":"NOOOOOO seleccionado"),duracion).show(); }
});
return ventanaDialogo.create(); case 1: Builder ventanaDialogo2 = new AlertDialog.Builder(this); ventanaDialogo2.setIcon(R.drawable.ic_launcher); ventanaDialogo2.setTitle("Ejemplo de cuadro diálogo 1 con texto" ); ventanaDialogo2.setPositiveButton("SI", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Context contesto = getBaseContext(); int duracion=Toast.LENGTH_SHORT; Toast.makeText(contesto,"OK seleccionado",duracion).show(); } }); ventanaDialogo2.setNegativeButton("NOOO", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Context contesto = getBaseContext(); int duracion=Toast.LENGTH_SHORT; Toast.makeText(contesto,"NOOOOOO seleccionado",duracion).show(); } }); ventanaDialogo2.setSingleChoiceItems(sexo,-1,new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Context contesto = getBaseContext(); int duracion=Toast.LENGTH_SHORT; Toast.makeText(contesto,sexo[which],duracion).show(); } }); return ventanaDialogo2.create(); case 2: barraSofisticadaDialogo = new ProgressDialog(this); barraSofisticadaDialogo.setIcon(R.drawable.ic_launcher); barraSofisticadaDialogo.setTitle("Hanciendo algo, no molesten!!"); barraSofisticadaDialogo.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); barraSofisticadaDialogo.setButton(DialogInterface.BUTTON_POSITIVE,"OK", new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(getBaseContext(), "Ok cliqueado",Toast.LENGTH_SHORT).show(); } });
return barraSofisticadaDialogo;
}//end case
return null;
}//end onCreateDialog
}