tinywebdb

31 views
Skip to first unread message

Dave Wolber

unread,
Feb 7, 2012, 12:41:55 PM2/7/12
to Android Programming at USF
Hi everyone. Here's a quick and dirty tinywebdb sample. Note that
usfwebservice.appspot.com is down due to overuse with App Engine, so
this uses appinvtinywebd.appspot.com...

Note also that what is returned in GotValue is a string even if you
put in a list, so for now at least you'll have to parse. We'll discuss
in class.



package com.javabridge.samples;

import java.util.ArrayList;

import
com.google.devtools.simple.runtime.components.android.ComponentContainer;
import com.google.devtools.simple.runtime.components.android.Form;
import com.google.devtools.simple.runtime.components.android.Label;
import
com.google.devtools.simple.runtime.components.android.TinyWebDB;

import android.app.Activity;
import android.os.Bundle;

public class TinyWebDBSampleActivity extends Form {
/** Called when the activity is first created. */

MyTinyWebDB webDB;
Label nameListLabel;
void $define ()
{
webDB = new MyTinyWebDB(this);
webDB.ServiceURL("http://appinvtinywebdb.appspot.com");
nameListLabel= new Label(this);
nameListLabel.Text("hello there");
ArrayList<String> list = new ArrayList<String>();
list.add("abc");
list.add("def");
webDB.StoreValue("wolberList", list); // note, this is for test
purposes, generally happens on event

webDB.GetValue("wolberList"); // request the data

}

class MyTinyWebDB extends TinyWebDB
{


@Override
public void WebServiceError(String message) {
// TODO Auto-generated method stub
super.WebServiceError(message);
nameListLabel.Text(message);
}

public MyTinyWebDB(ComponentContainer container) {
super(container);
// TODO Auto-generated constructor stub
}

@Override
public void GotValue(String tagFromWebDB, Object valueFromWebDB) {
ArrayList<String> list;
// list = (ArrayList<String>) valueFromWebDB;
//nameListLabel.Text(list.toString());
String s = (String) valueFromWebDB; // we know its a string of
form [x,y]

nameListLabel.Text(s);
String[] items = s.split(",");
nameListLabel.Text(items[0]);

}


}

}

bernhard

unread,
Feb 8, 2012, 9:55:07 PM2/8/12
to Android Programming at USF
hi,

String s = (String) valueFromWebDB; // we know its a string of form
[x,y]
crashes my app.
I have to do valueFromWebDB.toString() to avoid that.

String[] items = s.split(","); is a bit rough - since there will be
additional spaces in
the single items...

best
bernhard

Dave Wolber

unread,
Feb 9, 2012, 12:09:06 AM2/9/12
to Android Programming at USF
Hi Bernhard. Yes, my sample is not meant to use directly, you know
what you're putting in with StoreValue and so you can parse it in a
custom way in the GotValue. Also can check type of returned value
with .Class.toString()

Dave

Bernhard Schelling

unread,
Feb 9, 2012, 12:24:05 AM2/9/12
to android-progr...@googlegroups.com
i must admit i just had copied to try it out :)
still wondering why the cast to string messes up...

bernhard

David W Wolber

unread,
Feb 9, 2012, 12:54:11 AM2/9/12
to android-progr...@googlegroups.com
what are you storing in StoreValue?

Bernhard Schelling

unread,
Feb 9, 2012, 2:26:36 AM2/9/12
to android-progr...@googlegroups.com

A string array...

Reply all
Reply to author
Forward
0 new messages