Android Question Focus on an EditText

nibbo

Active Member
Licensed User
Longtime User
Hi, I am working with a multi column scrollview. Each line in the scrollview has an edittext.
When the scrollview is touched (or one of the labels in the row clicked) I want to set the focus to the edittext control on that row.
I am able, using the label click event, to construct the tag name for the edittext but cannot find how to set the focus of a control using it's tag.
Many thanks
 
What are you storing in your Tag? You need to get the edittext object, then you can do EditText.RequestFocus.
 
Upvote 0
Thanks Steve
The tag for the edit control is made up of a fixed string (i.e. "etName") and a number which happens to be the row within the scrollview.
All other controls (labels) in the row have a tag name of just the row number so I can derive the edittext control's tag name in the but I am unsure how to get a control using its tag name.
 
Upvote 0
... but cannot find how to set the focus of a control using it's tag.
You can't.
You can get the EditText with ScrollView1.Panel.GetView(Index)
The index depends on how you filled the ScrollView.
The view index begins with 0 and is incremented by one each time you add a new view.
Example: If have on each line a Label, an EditText and a CheckBox.
The Tag property of each view is the row index.
View Line Index
Label0____ 0 0
EditText0 _ 0 1
CheckBox0 0 2
Label1____ 1 3
EditText1_ 1 4
CheckBox1 1 5
Label2____ 2 6
EditText2_ 2 7
CheckBox2 2 8

The the index of EditText2 in row 2: rowIndex * 3 + 1 = 2 * 3 + 1 = 7
Code: Copy
Dim edt As EditText
edt = ScrollView1.Panel.GetView(row * 3 + 1)
edt.RequestFocus
In this example 3 is the number of views per row.
 
Upvote 0
You can't. If you are storing various data in a tag I suggest you use a Type, you can then store the Edittext object and other data and get it directly.
 
Upvote 0
Thanks for all of the replies, they helped a lot; the final solution if anyone else needs it...
Each row in the scrollview is a panel with three labels and an edit text, all of which have their tag set to the row number.
For each label click event I call a common sub routine that uses the tag value to determine the row thus...
Code: Copy
Sub ProcessLabelClick(lbl As Label)
    Dim pnl As Panel
    pnl = scrollViewName.Panel.GetView(lbl.Tag)
    Dim et As EditText
    et = pnl.GetView(3)
    et.RequestFocus
End Sub
Thanks again.

The next bit is how to make the keyboard appear when the edittext gets focus...
 
Upvote 0
Just to update the above. Using IME and show keyboard will set the focus to the required edit text and show the keyboard so replace the et.RequestFocus with:
Code: Copy
Dim inputMethod As IME
inputMethod.Initialize("")
inputMethod.ShowKeyboard(et)
 
Upvote 0
Back
Top