Skip to main content

Adding an Android View to a LWUIT Form

7 replies [Last post]
ugochirico
Offline
Joined: 2009-11-04
Points: 0

Hi,
I just ported my J2ME/LWUIT app on Android. All works perfectly.
Now I have to integrate a library that returns me an Android View, mainly the AdMob SDK that returns me an AdView derived from View.
This is the class hierarchy:

<a href="http://developer.android.com/reference/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</a>
     <img src="///D:/Documenti/Download/googleadmobadssdkandroid/GoogleAdMobAdsSdkAndroid-4.0.4/docs/resources/inherit.gif" alt="extended by " /><a href="http://developer.android.com/reference/android/view/View.html?is-external=true" title="class or interface in android.view">android.view.View</a>
          <img src="///D:/Documenti/Download/googleadmobadssdkandroid/GoogleAdMobAdsSdkAndroid-4.0.4/docs/resources/inherit.gif" alt="extended by " /><a href="http://developer.android.com/reference/android/view/ViewGroup.html?is-external=true" title="class or interface in android.view">android.view.ViewGroup</a>
               <img src="///D:/Documenti/Download/googleadmobadssdkandroid/GoogleAdMobAdsSdkAndroid-4.0.4/docs/resources/inherit.gif" alt="extended by " /><a href="http://developer.android.com/reference/android/widget/RelativeLayout.html?is-external=true" title="class or interface in android.widget">android.widget.RelativeLayout</a>
                      <img src="///D:/Documenti/Download/googleadmobadssdkandroid/GoogleAdMobAdsSdkAndroid-4.0.4/docs/resources/inherit.gif" alt="extended by " /><b>com.google.ads.AdView</b>

I have to add such a View to an LWUIT Form as a component (mainly at the top or at the bottom of the Form).
How can I do that?
Ugo Chirico

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
thorsten_s
Offline
Joined: 2008-08-15
Points: 0

One option would be to use LWUIT's PeerComponent feature. That is really new and is a little problematic as you have to be careful with the whole threading business. Read the com.sun.lwuit.impl.android.AndroidImplementation.java (at line

1260) on how to use it.  Create your android view on the Android UI thread and the LWUIT component on the EDT.<br />

The other option would be to place the com.sun.lwuit.impl.android.AndroidView within an Android layout where you place your custom Android view above or below. That is, you would completely bypass LWUIT.

ugochirico
Offline
Joined: 2009-11-04
Points: 0

Hi Thorsten,
I created an LWUIT component from a Android view, following your suggestion, by using PeerComponent.create. I set the preferred size, called setVisible(true) and added the component to my form with BorderLayout, but I don't see the android view in my form. Do you have any idea?
This is my snippet:
Looper.prepare(); // needed to create an Android view inside the EDT

TextView tv = new TextView(activity);
tv.setText("ciao ciao");

Component adComponent = PeerComponent.create(tv);
adComponent.setPreferredH(50);
adComponent.setPreferredW(320);
adComponent.setVisible(true);
adComponent.getStyle().setBorder(Border.createDottedBorder(2, 0x999999));

this.addComponent(BorderLayout.SOUTH, adComponent);

abuhmead1987
Offline
Joined: 2010-04-21
Points: 0

please help me to start developing andrid apps using lwuit

abuhmead1987
Offline
Joined: 2010-04-21
Points: 0

Hello Gyus,
I'm searching more and more to find some one tell me how to start developing android apps with lwuit, but, sadly no one answer, is it complication to no one tried or no one know,
please if you know or you know any link can guide me don't hesitate to tell me
Best Regards,

ugochirico
Offline
Joined: 2009-11-04
Points: 0

I'm going to write a new post on my blog (http://www.ugochirico.com) about compiling LWUIT for android using ADT (eclipse) and writing an LWUIT application for android.
Give me a couple of days.

hotszkin
Offline
Joined: 2008-11-23
Points: 0

Hi ugochirico,

I have read your blog and now I want to try to recompile the LWUIPortAndroid (Just recompile it, no updated code). I open the project in eclipse, fix the JRE version and android.jar path, but it still get many warnings in the project. Most of them are something like "Vector is a raw type. References to a generic type Vector <E> should be parameterized". Do you know what is wrong? My JRE version is 7 and jdk compliance level is set to 1.6.

Thanks.

ugochirico
Offline
Joined: 2009-11-04
Points: 0

Hi,

there's nothing wrong. LWUIT has been wrote for J2ME where parametrizable vectors and collections doesn't exists, i.e. you must use generic vectors. While in java 7 vectors, hashtables and other collections should be parametrized. Android SDK is built upon Java 6 and thus it warns when you use generic vectors, but there's no problem. The code is good and works correctly.

Regards,

Ugo Chirico
http://www.ugochirico.com