Recent

Author Topic: Edit.SetFocus in laz4android  (Read 3566 times)

polypress

  • Jr. Member
  • **
  • Posts: 91
Edit.SetFocus in laz4android
« on: March 26, 2017, 01:14:35 pm »
I think this is the correct part of the forum for this subject, but if not, then please advise.
I would like to set focus on an edit control as soon as the app is started, but the Edit1.setFocus does not work. I have tried ActivityControl:=Edit1;, Edit1Click(Sender);,
 Edit1.Focused;, Edit1.CanFocus;,
SendMessage(Edit1.Handle, $0001, 0, 0);,
 Edit1.Perform(EM_LINEINDEX, 1, 0);,
Edit1.PerformTab(true);,  Edit1.Text:='  ';, Edit1.SelectAll;
but none will send focus to Edit1; it will only focus when the control is clicked.
I have studied LCLActivity.java to try to identify a solution in this. I have found requestFocus and setFocusableInTouchMode(true); but do not know how to reach these specifically in code for Edit1.

Does anyone have a solution to achieve Edit1.setFocus, or provide a detailed tutorial on LCLActivity.java to enable a solution?

Any contributions would be gratefully received.

Regards
 

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: Edit.SetFocus in laz4android
« Reply #1 on: March 26, 2017, 03:57:35 pm »
I would like to set focus on an edit control as soon as the app is started, but the Edit1.setFocus does not work. I have tried ActivityControl:=Edit1;
Last valid: Form.ActiveControl := Edit1
Need the source code to find why is not working for you

polypress

  • Jr. Member
  • **
  • Posts: 91
Re: Edit.SetFocus in laz4android
« Reply #2 on: March 26, 2017, 04:37:04 pm »
Thanks for your reply.

I've tried with Form1.ActiveControl:=Edit1; but it still doesn't work.

The relevant part of the code is as follows :-


procedure TInvoicer1.Button9Click(Sender: TObject);
begin
  if (Button9.Caption='Show') then begin
                              Button9.Caption:='Hide';
                              AlStringGrid6.Visible:=true;
                              HideKeys;
                              end else begin
                              Button9.Caption:='Show';
                              AlStringGrid6.Visible:=false;
                              doSound;
                              Edit1.SetFocus;
                              ActiveControl:=Edit1;
//                              Edit1.Focused;
//                              Edit1.CanFocus;
//                              SendMessage(Edit1.Handle, $0001, 0, 0);
//                              Edit1.Perform(EM_LINEINDEX, 1, 0);
//                              Edit1.PerformTab(true);
//                              Edit1.Text:='Here';
//                              Edit1Click(Sender);
//                              Edit1.SelectAll;
                              ShowKeys;
                              end;
end;

The doSound;, HideKeys;, ShowKeys; work perfectly well; it's just the Edit1.SetFocus; etc. which don't work;

I have tried it on a much smaller, basic app and get the same result.

Regards

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: Edit.SetFocus in laz4android
« Reply #3 on: March 26, 2017, 04:51:05 pm »
Try only one form with two Edit1, Edit2 and only one line of code ActiveControl := Edit2.

polypress

  • Jr. Member
  • **
  • Posts: 91
Re: Edit.SetFocus in laz4android
« Reply #4 on: March 28, 2017, 10:39:57 am »
I keep getting "error in script" when I write this for each character written. Is it a website problem or a problem on my computer.

I have tried as you suggest, ASerge, but still get the same result - no focus until control is clicked.

Regards

polypress

  • Jr. Member
  • **
  • Posts: 91
Re: Edit.SetFocus in laz4android
« Reply #5 on: April 04, 2017, 10:27:30 am »
Does anyone understand the logic of the LCLActivity.java code sufficiently to explain how each control (in particular, EditText control) is accessed? If I can understand this, then I hope I should be able to set this to focus by the "requestFocus" method.

I have tried understanding the logic of the code, but cannot follow it through.


I keep getting "error in script" when I write this for each character written. Is it a website problem or a problem on my computer.


The problem of "error in script" seems to have disappeared now.

Regards

 

TinyPortal © 2005-2018