2

I use codenameone and I wanna change some labels text's or fill table with dynamic data from database. So, my question is :

1.what event is good for change component text on showing form?

2.how to create database and load data from it or insert data into it?

My application detail: I've a Main form with list of buttons that every button mapped to show another form. components of forms except Main form have to be set dynamicly.

Ahmad
  • 437
  • 5
  • 20

2 Answers2

0

If you are using the GUI builder you have the beforeShow event where you can do just that. If you use code then just do that stuff before you call form.show().

I suggest you work with the Storage class if your needs are simple, it supports storing simple objects. You can also use SQlite database on smartphones (not J2ME etc.) but that is an overkill for most. Both are well documented in the Codename One developer guide.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Thanks a lot Shai. I tried to do what you said and I got error "An internal application error occurred: java.lang.NullPointer". this is some lines of my code (generated with guibuilder of codenameone in StateMachineBase.java class): public com.codename1.ui.Label findLblTimeValue() { return (com.codename1.ui.Label)findByName("lblTimeValue", Display.getInstance().getCurrent()); } protected void beforeReminderUI(Form f) { findLblTimeValue().setText("Hi"); } – Ahmad Nov 01 '12 at 06:02
  • You can use findLblTimeValue(f), since the form isn't showing yet (this is the before method) the Display.getCurrent() method will return the previous form that doesn't contain LblTimeValue in it. – Shai Almog Nov 01 '12 at 10:08
0

Thanks Shai. As Shai said, to set value to components of form we can do this before form.Show().

I got error because I called findLblTimeVlaue() but when I changed it to findLblTimeVlaue(String, Form) my error gone. this is the code:

@Override
protected void beforeReminderUI(Form f) {
    com.codename1.ui.Label lbl = 
            (com.codename1.ui.Label)findByName("lblTimeValue", f);
    lbl.setText("Hi 2013213");
}
Ahmad
  • 437
  • 5
  • 20