Android Question CustomView issues

jfranz

Member
Licensed User
Longtime User
I have created a simple CustomView and attempted to add it to a layout. Everything seems to work correctly in the designer allowing me to create it and include it in the script. However, I have 2 issues with this.

The first one is I'm unable to set the EditText.Color value using the supplied Lbl view in the DesignerCreateView sub. I have to set it to Colors.White and not Lbl.Color because it gives me a "Property: Color is writeonly" error.

Here is an example, notice I have it hardcoded to Colors.White right now.
B4X:
    mEditText.Color = Colors.White
    'mEditText.Color = Lbl.Color

The second issue is that when the LoadLayout is done I get a ClassNotFoundException which points to my new class. It references b4a.example.numupdnview which is the class but I have it declared as NumUpDnView.

I have included a copy of the class to help determine what I'm doing wrong. I understand that I could do this without a customView but I need to do this in multiple spots and thus wrapping it up makes more sense.

Thanks for any help with this.
 

Attachments

  • UpDnNumber.bas
    13.2 KB · Views: 352

klaus

Expert
Licensed User
Longtime User
Attached a modified version.
You missed the principle to make a class usable in the Designer !
You need two routines:
- Initialize
- DesignerCreateView

To be able to also add the view in the code I added a Show routine.
The initialization of the view is done in the Init routine.

Unfortunately you cannot get the Color from Lbl in the Designer.
I added this color as a property.

I haven't tested everything nor updated all routines but just to show the principle.

Best regards.
 

Attachments

  • UpDnNumber.zip
    10.5 KB · Views: 235
Upvote 0

jfranz

Member
Licensed User
Longtime User
ok, this is a little embarrassing. I included the wrong file. The one I included was an example that I had started from another example of a dropdown control and hadn't finished. I needed to get the activity from the CustomView somehow and hadn't figured that out yet. I need to return to that but thought I would do something easy first and make a little progress and hopefully figure it out as I went.

My code had both the Initialize and DesignerCreateView and I couldn't figure out what you were talking about until I looked over your example. Thanks for replying but my question still exists.

So If I understand your replay about the colors there is a Textcolor property available; and the designer has a background color called Color which you can set but can't use in the CustomView. Is this a bug in the base class that only has a WriteOnly property? Since I haven't searched for it exactly does Erel plan on exposing it as a read/write property in a future version?

It's kind of tough to make a reusable object and use the designer but yet have to remember to handle all the strange things that were left out each time I use it.

For my info, is the CallbackModule in the initialize the same as the Activity? If this is the case then I can extend the MLComboBox class written by HotShoe to support the designer.

Again, sorry for the mix up with the original code. Trying to multi task and I messed up.

Thanks again for the reply.
 

Attachments

  • NumUpDnView.bas
    3.2 KB · Views: 253
Upvote 0

klaus

Expert
Licensed User
Longtime User
Attached you find a modified version.

The Lbl Label in the DesignerCreateView routine is not a 'true' Label it's only used to transmit the Text properiteis.
It doesn't have a Background property.
You should use the Panel color for this.

Color property, have a look here Get Color(of a label):
When you set, in B4A, a Color propety it means in reality you set the Background as a ColorDrawable object.
I added in your project Erel's routine from post #10 in the link above.

For my info, is the CallbackModule in the initialize the same as the Activity?
No ! CallbackModule is the Module where the CustomView is initialized in the Example Me which means Main. It's not the Activity.

Best regards.
 

Attachments

  • NumUpDnView2.zip
    8.4 KB · Views: 266
Upvote 0

jfranz

Member
Licensed User
Longtime User
Klaus, thanks very much for the help. I remember seeing the color thing last spring and totally forgot about it. After reading Erel's post I remembered it again. Its just such a strange limitation until you realize the main issue behind getting the color.

It works in the project you created but it still errors out in my project with the same error. I think I will need to create a new project and see if I can recreate it or get it to fail. Its just a prototype so far so not a huge amount of work to recreate everything again.

Again thanks.
 
Upvote 0

jfranz

Member
Licensed User
Longtime User
I figured why I was getting the java ClassNotFoundException finally. If you create a CustomView and assign a class to it but don't export the view into the code you get the error. Granted normally you would do this so you can deal with the view but sometimes when you first are creating the form and before connecting the data up with the views you go after the UI. I verified this by commenting out the declaration in the Globals and again got the error.

Thanks Klaus again for your help.
 

Attachments

  • MyList.zip
    10.1 KB · Views: 247
Upvote 0
Top