B4A Library MSMaterialEditText

Edit: See this post for imho a better B4A implementation.
-------------------------------------------------------------------------------------------------
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. It looks the same as a standard EditText. It doesn't look like it is using a different theme.
2. It is not possible to inherit the documentation as you don't have the source code. Sorry.
3. This is the "initialize" method of EditTextWrapper:
B4X:
@Override
   @Hide
   public void innerInitialize(final BA ba, final String eventName, boolean keepOldObject) {
     super.ba = ba;
     if (!keepOldObject)
       setObject(new EditText(ba.context));
     super.innerInitialize(ba, eventName, true);
     if (ba.subExists(eventName + "_textchanged")) {
       TextWatcher watcher = new TextWatcher() {
         private CharSequence old;
         @Override
         public void afterTextChanged(Editable s) {
           ba.raiseEvent2(getObject(), false, eventName + "_textchanged", true,
               old, getObject().getText().toString());
         }

         @Override
         public void beforeTextChanged(CharSequence s, int start,
             int count, int after) {
           old = s.toString();
         }

         @Override
         public void onTextChanged(CharSequence s, int start,
             int before, int count) {
         }
         
       };
       getObject().addTextChangedListener(watcher);
     }
     if (ba.subExists(eventName + "_enterpressed")) {
       OnEditorActionListener o = new OnEditorActionListener() {

         @Override
         public boolean onEditorAction(TextView v, int actionId,
             KeyEvent event) {
           ba.raiseEvent(getObject(), eventName + "_enterpressed");
           return false;
         }
         
       };
       getObject().setOnEditorActionListener(o);
     }
     if (ba.subExists(eventName + "_focuschanged")) {
       getObject().setOnFocusChangeListener(new View.OnFocusChangeListener() {

         @Override
         public void onFocusChange(View v, boolean hasFocus) {
           ba.raiseEventFromUI(getObject(), eventName + "_focuschanged", hasFocus);
         }
       });
     }
   }
You can add code after: super.innerInitialize(ba, eventName, true);
 

thedesolatesoul

Expert
Licensed User
Longtime User
1. Interstingly that doesnt happen on my phone. Maybe it is a manufacuter issue but I cant see how. (Screenshot 1st is a normal edit text, second is the MSMaterialEditText).
2. Can the doclet extract the documentation from the jar? If not, is it possible to make it extract it from the xml? Or is it possible to write a tool that can extract it from the superclass xml and insert it into subclass xml? I am thinking of writing some helper tools if I get the time.
3. I see. So I can override innerInitialize instead of Initialize. Are these essentially the same (i.e. the sub in B4A Initialize = innerInitialize method)?
The reason I ask this is that ViewWrapper has the Initialize method which does call innerInitialize method in its own class, but I dont understand when innerInitialize is called in the EditTextWrapper class. (Edit: Sorry this is because this method is overridden! ok!)
What I wanted to know if I could override a method from a grandparent class (in this case Initialize is in ViewWrapper not TextViewWrapper). I guess is not possible. (But I dont need to if I can use innerInitialize).
Thank you.
 

Attachments

  • Screenshot_2014-09-21-23-43-50[1].png
    Screenshot_2014-09-21-23-43-50[1].png
    52.8 KB · Views: 440

Erel

B4X founder
Staff member
Licensed User
Longtime User
the sub in B4A Initialize = innerInitialize method
Not in the general case. Only in subclasses of ViewWrapper.

innerInitialize is called for both manually created views and designer created views.

Can the doclet extract the documentation from the jar? If not, is it possible to make it extract it from the xml?
1. No. 2. There are no such plans for now.
Technically you can create a program that takes the documentation from one XML file and adds it to the second.
 

thedesolatesoul

Expert
Licensed User
Longtime User
Not in the general case. Only in subclasses of ViewWrapper.

innerInitialize is called for both manually created views and designer created views.


1. No. 2. There are no such plans for now.
Technically you can create a program that takes the documentation from one XML file and adds it to the second.
I see. I am still trying to figure out why your override innerInitialize and not Initialize. Is it because innerInitialize will be run for Designer views but Initialize will not?
It makes sense.

I have some ideas to write some helper apps (like SLC) for libraries/samples/workspace creation, I might take a stab at parsing the xml if I get time.

Thank you for your time.
 

Theera

Well-Known Member
Licensed User
Longtime User
Hi Thedesolatesoul,
How to use editText1.HintLabel in MSMaterialEditText-B4A which is differ from your example by using MSMaterialEditText library?
My code has problem.

B4X:
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Text="EditText"
    EditText1.HintLabel= lbl
 

thedesolatesoul

Expert
Licensed User
Longtime User
Hi Thedesolatesoul,
How to use editText1.HintLabel in MSMaterialEditText-B4A which is differ from your example by using MSMaterialEditText library?
My code has problem.

B4X:
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Text="EditText"
    EditText1.HintLabel= lbl
You dont need to initialize a new label, there is a HintLabel already initialized and ready to use inside the library.
I only exposed the HintLabel so you can customize it as you like.
You can just do:
B4X:
EditText1.HintLabel.Text = "My Hint Text"
or
B4X:
EditText1.HintLabel.TextSize = 22
as an example.
 

anallie0

Active Member
Licensed User
Longtime User
Hi
I'm using 9 MSMaterialEditText in a ScrollView, 8 have a height of 60 dip
the ninth must contain notes and I wanted it high 200 dip.

how I can raise only the text box with the label on the top left?

screen.png
 

thedesolatesoul

Expert
Licensed User
Longtime User
Hi
I'm using 9 MSMaterialEditText in a ScrollView, 8 have a height of 60 dip
the ninth must contain notes and I wanted it high 200 dip.

how I can raise only the text box with the label on the top left?

View attachment 32626
Its tricky with a multiline edit text.

Try this version.
 

Attachments

  • MSMaterialEditText-B4A.zip
    4.1 KB · Views: 236

anallie0

Active Member
Licensed User
Longtime User
Hi
Use this code to control the input, but does not work and gives me error "Unknown member:selectionstart"
B4X:
Sub MET1_TextChanged (Old As String, New As String)
If New.Length > 20 Then 
MET1.text = Old
MET1.SelectionStart =MET1.Text.Length 
   End If
End Sub
 

thedesolatesoul

Expert
Licensed User
Longtime User
Hi
Use this code to control the input, but does not work and gives me error "Unknown member:selectionstart"
B4X:
Sub MET1_TextChanged (Old As String, New As String)
If New.Length > 20 Then
MET1.text = Old
MET1.SelectionStart =MET1.Text.Length
   End If
End Sub

You can retrieve the full edit text from the MaterialEditText class using: MET1.AsEditText
B4X:
Met1.AsEditText.SelectionStart = Met1.AsEditText.Text.Length
 
Top