App inventor 2 en español
Cómo programar los teléfonos móviles con Android.
Curso de App inventor 2 en español - Juan Antonio Villalpando
-- Tutorial de iniciación de App Inventor 2 en español --
Volver al índice del tutorial
_________________________________________________
118.- Java Bridge. VisorDeLista. Notificador. Archivo. TinyDB. MiniWebDB.
- VisorDeLista: funciona.
- Notificador: funciona.
- Archivo: funciona.
- TinyDB: no funciona. Lee valor, pero no deja escribirlo.
- MiniWebDB: no crea el archivo java. No funciona.
_____________________________________________________
VisorDeLista.aia
_____________________________________________________
- Diseño.
_____________________________________________________
- Bloques.
_____________________________________________________
- Conversion a Java.
- Pulsamos en "Generate Java"
- Pulsamos en JAVA FILE.
Screen1.java |
package juan.com.visordelista; // Cambia por tu package.
import com.google.appinventor.components.runtime.HandlesEventDispatching;
import com.google.appinventor.components.runtime.EventDispatcher;
import com.google.appinventor.components.runtime.Form;
import com.google.appinventor.components.runtime.Component;
import com.google.appinventor.components.runtime.ListView;
import com.google.appinventor.components.runtime.Label;
import com.google.appinventor.components.runtime.Notifier;
import com.google.appinventor.components.runtime.File;
import com.google.appinventor.components.runtime.TinyDB;
class Screen1 extends Form implements HandlesEventDispatching {
private ListView VisorDeLista1;
private Label Etiqueta1;
private Notifier Notificador1;
private File Archivo1;
private TinyDB TinyBD1;
protected void $define() {
this.AppName("VisorDeLista2");
this.Title("VisorDeLista - Juan A. Villalpando");
VisorDeLista1 = new ListView(this);
VisorDeLista1.ElementsFromString("Notificador, Archivo Escribir, Archivo Leer, TinyDB Escribir, TinyDB Leer");
Etiqueta1 = new Label(this);
Etiqueta1.FontBold(true);
Etiqueta1.FontSize(22);
Etiqueta1.Text("Texto para Etiqueta1");
Etiqueta1.TextColor(0xFF0000FF);
Notificador1 = new Notifier(this);
Archivo1 = new File(this);
TinyBD1 = new TinyDB(this);
EventDispatcher.registerEventForDelegation(this, "AfterPickingEvent", "AfterPicking" );
EventDispatcher.registerEventForDelegation(this, "GotTextEvent", "GotText" );
}
public boolean dispatchEvent(Component component, String componentName, String eventName, Object[] params){
if( component.equals(VisorDeLista1) && eventName.equals("AfterPicking") ){
VisorDeLista1AfterPicking();
return true;
}
if( component.equals(Archivo1) && eventName.equals("GotText") ){
Archivo1GotText((String)params[0]);
return true;
}
return false;
}
public void VisorDeLista1AfterPicking(){
if(VisorDeLista1.SelectionIndex()==1){
Notificador1.ShowAlert("Ejemplo de Notificador."); // Manual
}
if(VisorDeLista1.SelectionIndex()==2){
Archivo1.AppendToFile("Esto es texto.", "prueba.txt");
}
if(VisorDeLista1.SelectionIndex()==3){
Archivo1.ReadFrom("prueba.txt");
}
if(VisorDeLista1.SelectionIndex()==4){
TinyBD1.StoreValue("valor", "12345");
}
if(VisorDeLista1.SelectionIndex()==5){
Etiqueta1.Text(String.valueOf(TinyBD1.GetValue("valor", "valor")));
}
}
public void Archivo1GotText(String texto){
Etiqueta1.Text(texto);
}
}
|
_____________________________________________________
__________________________________
|