Recent

Author Topic: LAMW - How to create EditText with (X) button clear  (Read 2885 times)

Agmcz

  • New Member
  • *
  • Posts: 19
LAMW - How to create EditText with (X) button clear
« on: October 06, 2021, 02:18:54 pm »
Hi all

How to create EditText with (X) button clear

an example is attached for more clarification...

jmpessoa

  • Hero Member
  • *****
  • Posts: 1988
Re: LAMW - How to create EditText with (X) button clear
« Reply #1 on: October 06, 2021, 07:28:19 pm »

Good suggestion!

I will try implement some new component like this!

Thank you!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Agmcz

  • New Member
  • *
  • Posts: 19
Re: LAMW - How to create EditText with (X) button clear
« Reply #2 on: October 06, 2021, 08:24:27 pm »
more...  :-[
copy text to clipboard.

Mongkey

  • Full Member
  • ***
  • Posts: 181
Re: LAMW - How to create EditText with (X) button clear
« Reply #3 on: October 07, 2021, 03:34:51 pm »
yes LAMW can do with only already created components,

if it doesnt fit your need you can create syntetic button using panel.

The most easiest is using recycler -> easy to manipulate.

Placing button background with image also can.

Beautifying with compound also great!

Many ways  :D

Oops, you could place button inside edittext, align rightend, set your button font with 5  smaller font than edittext. You can create many buttons inside, set your button background with 0% color png, it does all magic
« Last Edit: October 07, 2021, 04:25:53 pm by Mongkey »

Mongkey

  • Full Member
  • ***
  • Posts: 181
Re: LAMW - How to create EditText with (X) button clear
« Reply #4 on: October 07, 2021, 04:18:27 pm »
 :D
« Last Edit: October 08, 2021, 01:14:50 am by Mongkey »

Mongkey

  • Full Member
  • ***
  • Posts: 181
Re: LAMW - How to create EditText with (X) button clear
« Reply #5 on: October 08, 2021, 12:39:39 am »
this is what u need, this demo using jlabel instead jbutton, but you can do both,
« Last Edit: October 08, 2021, 01:07:41 am by Mongkey »

Mongkey

  • Full Member
  • ***
  • Posts: 181
Re: LAMW - How to create EditText with (X) button clear
« Reply #6 on: October 08, 2021, 12:47:14 am »
 :), all controls seem to be clickable, so you can treat them as button for clipboard ing or something
« Last Edit: October 08, 2021, 12:49:45 am by Mongkey »

Mongkey

  • Full Member
  • ***
  • Posts: 181
Re: LAMW - How to create EditText with (X) button clear
« Reply #7 on: October 08, 2021, 01:20:30 am »
Code: Pascal  [Select][+][-]
  1. {hint: Pascal files location: ...\modbus\jni }
  2. unit u_main;
  3.  
  4. {$mode delphi}
  5.  
  6. interface
  7.  
  8. uses
  9.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  10.   cthreads,
  11.   {$ENDIF}{$ENDIF}
  12.   Classes, SysUtils, AndroidWidget, tcpsocketclient, Laz_And_Controls;
  13.  
  14. type
  15.  
  16.   { TAndroidModule1 }
  17.  
  18.   TAndroidModule1 = class(jForm)
  19.     jButton1: jButton;
  20.     jEditText1: jEditText;
  21.     jTCPSocketClient1: jTCPSocketClient;
  22.     jTextView1: jTextView;
  23.     jTextView2: jTextView;
  24.     jTextView3: jTextView;
  25.     procedure AndroidModule1JNIPrompt(Sender: TObject);
  26.     procedure jButton1Click(Sender: TObject);
  27.     procedure jTCPSocketClient1BytesReceived(Sender: TObject;
  28.       var jbytesReceived: TDynArrayOfJByte);
  29.     procedure jTCPSocketClient1Connected(Sender: TObject);
  30.     procedure jTCPSocketClient1MessagesReceived(Sender: TObject;
  31.       messageReceived: string);
  32.   private
  33.     {private declarations}
  34.   public
  35.     {public declarations}
  36.   end;
  37.  
  38. var
  39.   AndroidModule1: TAndroidModule1;
  40.  
  41. implementation
  42.  
  43. {$R *.lfm}
  44.  
  45.  
  46. { TAndroidModule1 }
  47.  
  48. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  49. begin
  50.   jTCPSocketClient1.ConnectAsync('192.168.0.18',502);
  51.   jTCPSocketClient1.SendMessage('tst');
  52. end;
  53.  
  54. procedure TAndroidModule1.AndroidModule1JNIPrompt(Sender: TObject);
  55. begin
  56.   jButton1.SetFontFromAssets('materialdesignicons-webfont.ttf');
  57.   jButton1.Text:='111'+self.ParseHtmlFontAwesome('f101');
  58.  
  59.   jTextView3.SetFontFromAssets('materialdesignicons-webfont.ttf');
  60.   jTextView3.Text:=self.ParseHtmlFontAwesome('f101');
  61. end;
  62.  
  63. procedure TAndroidModule1.jTCPSocketClient1BytesReceived(Sender: TObject;
  64.   var jbytesReceived: TDynArrayOfJByte);
  65. begin
  66. end;
  67.  
  68. procedure TAndroidModule1.jTCPSocketClient1Connected(Sender: TObject);
  69. begin
  70.   jtextview1.Text:='connected';
  71. end;
  72.  
  73. procedure TAndroidModule1.jTCPSocketClient1MessagesReceived(Sender: TObject;
  74.   messageReceived: string);
  75. begin
  76.   jtextview2.Text:=messageReceived;
  77. end;
  78.  
  79. end.

Code: Pascal  [Select][+][-]
  1. object AndroidModule1: TAndroidModule1
  2.   MarginLeft = 0
  3.   MarginTop = 0
  4.   MarginRight = 0
  5.   MarginBottom = 0
  6.   Enabled = True
  7.   Left = 395
  8.   Top = 145
  9.   Width = 320
  10.   Height = 400
  11.   Text = 'AndroidModule1'
  12.   ActivityMode = actMain
  13.   BackgroundColor = colbrDefault
  14.   ActionBarTitle = abtDefault
  15.   AnimationDurationIn = 1500
  16.   AnimationDurationOut = 1500
  17.   AnimationMode = animNone
  18.   OnJNIPrompt = AndroidModule1JNIPrompt
  19.   object jTextView1: jTextView
  20.     MarginLeft = 5
  21.     MarginTop = 5
  22.     MarginRight = 5
  23.     MarginBottom = 5
  24.     Enabled = True
  25.     Left = 5
  26.     Top = 5
  27.     Width = 61
  28.     Height = 20
  29.     Visible = True
  30.     PosRelativeToAnchor = []
  31.     PosRelativeToParent = [rpTop, rpLeft]
  32.     LayoutParamWidth = lpWrapContent
  33.     LayoutParamHeight = lpWrapContent
  34.     Text = 'jTextView1'
  35.     Alignment = taLeft
  36.     BackgroundColor = colbrDefault
  37.     FontColor = colbrDefault
  38.     FontSize = 0
  39.     TextTypeFace = tfNormal
  40.     FontSizeUnit = unitDefault
  41.     GravityInParent = lgNone
  42.   end
  43.   object jButton1: jButton
  44.     MarginLeft = 5
  45.     MarginTop = 5
  46.     MarginRight = 5
  47.     MarginBottom = 5
  48.     Enabled = True
  49.     Left = 5
  50.     Top = 35
  51.     Width = 80
  52.     Height = 50
  53.     Visible = True
  54.     Anchor = jTextView1
  55.     PosRelativeToAnchor = [raBelow]
  56.     PosRelativeToParent = [rpLeft]
  57.     LayoutParamWidth = lpOneQuarterOfParent
  58.     LayoutParamHeight = lpWrapContent
  59.     Text = 'jButton1'
  60.     BackgroundColor = colbrDefault
  61.     FontColor = colbrDefault
  62.     FontSize = 0
  63.     FontSizeUnit = unitDefault
  64.     GravityInParent = lgNone
  65.     OnClick = jButton1Click
  66.   end
  67.   object jTextView2: jTextView
  68.     MarginLeft = 5
  69.     MarginTop = 5
  70.     MarginRight = 5
  71.     MarginBottom = 5
  72.     Enabled = True
  73.     Left = 5
  74.     Top = 95
  75.     Width = 61
  76.     Height = 20
  77.     Visible = True
  78.     Anchor = jButton1
  79.     PosRelativeToAnchor = [raBelow]
  80.     PosRelativeToParent = [rpLeft]
  81.     LayoutParamWidth = lpWrapContent
  82.     LayoutParamHeight = lpWrapContent
  83.     Text = 'jTextView2'
  84.     Alignment = taLeft
  85.     BackgroundColor = colbrDefault
  86.     FontColor = colbrDefault
  87.     FontSize = 0
  88.     TextTypeFace = tfNormal
  89.     FontSizeUnit = unitDefault
  90.     GravityInParent = lgNone
  91.   end
  92.   object jEditText1: jEditText
  93.     MarginLeft = 10
  94.     MarginTop = 5
  95.     MarginRight = 5
  96.     MarginBottom = 5
  97.     Enabled = True
  98.     Left = 10
  99.     Top = 125
  100.     Width = 80
  101.     Height = 39
  102.     Visible = True
  103.     Anchor = jTextView2
  104.     PosRelativeToAnchor = [raBelow]
  105.     PosRelativeToParent = [rpLeft]
  106.     LayoutParamWidth = lpOneQuarterOfParent
  107.     LayoutParamHeight = lpWrapContent
  108.     Alignment = taLeft
  109.     InputTypeEx = itxText
  110.     MaxTextLength = -1
  111.     BackgroundColor = colbrDefault
  112.     FontColor = colbrDefault
  113.     FontSize = 0
  114.     Hint = 'search'
  115.     HintTextColor = colbrLightSteelBlue
  116.     ScrollBarStyle = scrNone
  117.     MaxLines = 1
  118.     HorScrollBar = True
  119.     VerScrollBar = True
  120.     WrappingLine = False
  121.     Editable = True
  122.     FontSizeUnit = unitDefault
  123.     CloseSoftInputOnEnter = True
  124.     CapSentence = False
  125.     CaptureBackPressed = False
  126.     GravityInParent = lgNone
  127.   end
  128.   object jTextView3: jTextView
  129.     MarginLeft = 5
  130.     MarginTop = 5
  131.     MarginRight = 5
  132.     MarginBottom = 5
  133.     Enabled = True
  134.     Left = 24
  135.     Top = 134
  136.     Width = 61
  137.     Height = 20
  138.     Visible = True
  139.     Anchor = jEditText1
  140.     PosRelativeToAnchor = [raAlignBaseline, raAlignRight]
  141.     PosRelativeToParent = []
  142.     LayoutParamWidth = lpWrapContent
  143.     LayoutParamHeight = lpWrapContent
  144.     Text = 'jTextView3'
  145.     Alignment = taLeft
  146.     BackgroundColor = colbrDefault
  147.     FontColor = colbrCrimson
  148.     FontSize = 0
  149.     TextTypeFace = tfNormal
  150.     FontSizeUnit = unitDefault
  151.     GravityInParent = lgNone
  152.   end
  153.   object jTCPSocketClient1: jTCPSocketClient
  154.     OnMessagesReceived = jTCPSocketClient1MessagesReceived
  155.     OnBytesReceived = jTCPSocketClient1BytesReceived
  156.     OnConnected = jTCPSocketClient1Connected
  157.     Left = 224
  158.     Top = 56
  159.   end
  160. end

jmpessoa

  • Hero Member
  • *****
  • Posts: 1988
Re: LAMW - How to create EditText with (X) button clear
« Reply #8 on: October 08, 2021, 11:46:42 pm »

Done!

Improved  jEditText component!

New!
Property: "ActionIconIdentifier"
events:  "OnActionIconTouchUp"  and "OnActionIconTouchDown"
Demo:  ""AppEditTextActionIconDemo1

Thanks!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Agmcz

  • New Member
  • *
  • Posts: 19
Re: LAMW - How to create EditText with (X) button clear
« Reply #9 on: October 10, 2021, 01:01:56 am »
Good job jmpessoa  :D
this is what i wanted.

Minor addition for demo:
Code: Pascal  [Select][+][-]
  1.   if jEditText1.GetTextLength() > 0 then
  2.   begin
  3.     if not jEditText1.IsActionIconShowing() then
  4.       jEditText1.ShowActionIcon();
  5.   end
  6.   else
  7.   begin
  8.     jEditText1.HideActionIcon();
  9.   end;
  10.  

 

TinyPortal © 2005-2018