simple question - dynamic text list

8 messages - 2093 views

Hello there...

first...respect for your hard work...you've done a top...

i searched a while an found some examples for generating dynamic fields / buttons and so on. But none worked....

 

I created this sample code based on the tutorial and some posts...

import org.kalmeo.kuix.core.Kuix;
import org.kalmeo.kuix.core.KuixConstants;
import org.kalmeo.kuix.core.KuixMIDlet;
import org.kalmeo.kuix.core.model.DataProvider;
import org.kalmeo.kuix.widget.Desktop;
import org.kalmeo.kuix.widget.Screen;
import org.kalmeo.kuix.widget.Text;
import org.kalmeo.kuix.widget.TextField;
import org.kalmeo.util.frame.Frame;

public class main extends KuixMIDlet implements Frame {

    DataProvider mydataProvider = new DataProvider();

    public void initDesktopStyles() {
        Kuix.loadCss("helloworld.css");
    }

    public void initDesktopContent(Desktop desktop) {
        Kuix.getFrameHandler().pushFrame(this);
        final Screen screen = Kuix.loadScreen("dynamic-display.xml", mydataProvider);
       
        screen.setTitle("Hello List");

        TextField item = new TextField();
       
        for (int i = 0; i < 5; i++) {
        Text t = new Text ("foo");
        t.setText("HELLO "+i);
        }
        screen.add(item);
        screen.setCurrent();
    }

    public boolean onMessage(Object identifier, Object[] arguments) {
        if ("exit".equals(identifier)) {
            main.getDefault().destroyImpl();
            return false;
        }

        if ("about".equals(identifier)) {
            Kuix.alert("D", KuixConstants.ALERT_OK);
            return false;
        }

        return true;
    }

    public void onAdded() {
    }

    public void onRemoved() {
    }
}

The XML:

<screen title="foobar">
    <container style="layout:borderlayout">
        <scrollPane horizontal="false" showscrollbar="true">
            <scrollpaneScrollbar></scrollpaneScrollbar>
            <scrollpaneContainer style="layout:borderlayout">

            <list>
            <_renderer><![CDATA[
                <textfield>@{foo}</textfield>
            ]]></_renderer>
            </list>

            </scrollpaneContainer>
        </scrollPane>
    </container>
    <screenFirstMenu onAction="exit">Exit</screenFirstMenu>
</screen>

Could someone explain me what i'm doing wrong?!

I only want an output like:

HELLO 1
HELLO 2
HELLO 3
HELLO 4
HELLO 5

thx

 

Hi!

You are not doing anything with the Text t that you create. It can't magically appear anywhere... Also, your approach is a little off. You should be constructing the dataprovider and adding items to that, not directly to the screen. Here is the initDesktopContent rewritten with the Kuix approach:

public void initDesktopContent(Desktop desktop) {
  Kuix.getFrameHandler().pushFrame(this);
   
  for (int i = 0; i < 5; i++) {
    DataProvider subProvider = new DataProvider();
    subProvider.setValue("foo", "HELLO " + i);
    mydataProvider.addItem("someItems", subProvider);
  }

  final Screen screen = Kuix.loadScreen("dynamic-display.xml", mydataProvider);

  screen.setTitle("Hello List");

  screen.setCurrent();
}

Going further with the design, you should, of course, create your own classes that inherit the DataProvider class to act as the business logic objects.

 

Hope this helps!

Thy for your reply...

 

this realy helps to understand...

But the subProvider has no method "setValue". I`m using kuix 1.1?!

Is it right that this method try`s to search for the tag "foo" in the xml and set its value to "hello"+i ?

This item is added to the mydataprovider and this one is added to the screen when i=4?!

 

 

EDIT:  i've read the multi dataprovider tut and think I`ve done a step forward,

Now i get the values in the list :)

but how do i get kuix to draw x list items...?  I believe that the xml is correct...

but where i have to put the function? and how ;)

I tried some loop statements but it doesent worked... :(

Some ideas?

 

thx

my new main class:


public class main extends KuixMIDlet implements Frame {

   // DataProvider mydataProvider = new DataProvider();

    public void initDesktopStyles() {
        Kuix.loadCss("helloworld.css");
    }

    public void initDesktopContent(Desktop desktop) {
        MasterDataProvider masterDataProvider = new MasterDataProvider();

        SlaveADataProvider sld = new SlaveADataProvider("second");
        masterDataProvider.addSlave(sld);
        Screen screen = Kuix.loadScreen("dynamic-display.xml", masterDataProvider);
        screen.setCurrent();
    }

    public boolean onMessage(Object identifier, Object[] arguments) {
       return false;
    }

    public void onAdded() {
    }

    public void onRemoved() {
    }
}

My DataProvider Class #1


public class MasterDataProvider extends DataProvider {

    protected Object getUserDefinedValue(String property) {
        if ("first_one".equals(property)) {
            return "first";
        }
        return super.getUserDefinedValue(property);
    }

}

Second one...


    public class SlaveADataProvider extends DataProvider {

    String name=".";

    public SlaveADataProvider(String name) {

    this.name = name;
    }


   protected Object getUserDefinedValue(String property) {
        if ("second_one".equals(property)) {
            return name;
        }
        return super.getUserDefinedValue(property);
    }


}

And the XML:

<screen style="layout:inlinelayout(false,fill)">
    <list>
    <listitem>${first_one}</listitem>
    <listitem>${second_one}</listitem>
    </list>
    <list>
    <_renderer><![CDATA[
                <listitem>${second_one}</listitem>
            ]]></_renderer>
    </list>
</screen>

 

Hi,

Sorry about my previous post, I forgot to include the XML which might be your missing link:

<screen title="foobar">
  <container style="layout:borderlayout">
  <scrollPane horizontal="false" showscrollbar="true">
  <scrollpaneScrollbar></scrollpaneScrollbar>
  <scrollpaneContainer style="layout:borderlayout">

  <list>
  <_renderer><![CDATA[
  <textfield>@{foo}</textfield>
  ]]></_renderer>
  <_items>@{someItems}</_items>
  </list>

  </scrollpaneContainer>
  </scrollPane>
  </container>
  <screenFirstMenu onAction="exit">Exit</screenFirstMenu>
</screen>

That with my previous Java code works well and should be able to get you started in the right direction. Especially notice the <_items> tag and its reference to someItems in my Java code.

Works fine...THANK YOU !!!!

Thank you very much for this great ui toolkot. But i get the same error, that setValue is not available. I looked in your repository and found out that someone has added you meanwhile. But the jars to download is from the last February. Is threre any source, where i can get a newer version of kuix? Thank you very much!!!

It works!!!!!!!!!!

 

I have checked out the repos and created a new jar library.

 

Just one thing, if i want to make the action dynamic.

<list>
  <_renderer><![CDATA[
  <listitem onAction="@{foo2}">
      <Text>@{foo2}</Text>
  </listitem>
  ]]></_renderer>
  <_items>@{someItems}</_items>
  </list>

But then foo2 is interpreted as an text, not as an variable.

I guess the syntax within " " is different.

 

Does anyone know how to do that?