LoadLayout in a class

stevel05

Expert
Licensed User
Longtime User
I'm probably trying to do something that is not supposed to work, but I have passed the activity to a class and then loaded a layout within the class. The layout is displayed and in the example attached, the DrawBtn_Click method fires as expected, but the EditText1_EnterPressed fails with the error Object should first be initialized.

If I initialize the views within the class, the DrawBtn_Click still fires, but the EditText_EnterPressed does not return the text, presumably a new EditText is created with the initialization.

It would be useful if this would work, but I imagine that it is down to differences in the complexity of the wrappers of each view.
 

Attachments

  • test.zip
    7.2 KB · Views: 310
Last edited:

stevel05

Expert
Licensed User
Longtime User
Wow, I think that may open a can of worms. You can iterate over the views and get the information, but I think you would have to rebuild the layout in code, effectively duplicating the layout as you would have to dim and initialize the variables somewhere.

Sounds like you are trying to write a generic handler.

Maybe someone has an idea how it might work.

Sent from my HTC Sensation XE with Beats Audio Z715e using Tapatalk 2
 
Upvote 0

Uitenhage

Member
Licensed User
Longtime User
Informatix (or Agraham?),

I used your "Yes_it_works2" example from this thread and it worked exactly as expected.
I tried to extend it to include LongClicks and got unexpected results . I cloned the SetOnClickListener line in the class Initialize Sub and changed it to SetOnLongClickListener. I cloned the Click subs in the class and in Main and changed all the Click references in the clones to LongClick. Now I expected the same behavior on a long click as a click. Click works as previously but long click produces a messagebox "Unfortunately, Layout change example has stopped".
Under Debug (legacy) this appears in the log:

Installing file.
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.NullPointerException
at android.view.View.showContextMenu(View.java:4545)
at android.view.View.performLongClick(View.java:4514)
at android.widget.TextView.performLongClick(TextView.java:9575)
at android.view.View$CheckForLongPress.run(View.java:18768)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5455)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)

What have I missed?

Compiled both in Release and Debug (legacy) using B4A v3.20 and Reflection 2.40 on a Galaxy S3.

Thanks,

Jim
 
Upvote 0
Top