I have a ListView
and in that ListView
I have a Row with some TextViews
and EditTexts
in it.
When I press anywhere on the row I want the EditText
to take focus so text can be entered.
The problem is that I cannot get this to work. When i place the EditText
in the ListView
the OnItemClick
will not respond when I click on the ListView
.
I tried using focusable="false"
on the EditText
and it allowed me to click on the ListView
again but I could not get the EditText
to get focus even after setting the focusable to true.
Next I tried using the android:descendantFocusability="beforeDescendants"
in the ListView
but it did not seem to make any change, it still wouldn't work.
Does anyone have an idea on what I can do to make it work?
Try this, it should let you click on a line and focus the EditText (modified from this SO Answer):
public void onItemSelected(AdapterView<?> listView, View view, int position, long id)
{
EditText yourEditText = (EditText) view.findViewById(R.id.youredittextid);
listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
yourEditText.requestFocus();
}
public void onNothingSelected(AdapterView<?> listView)
{
// onNothingSelected happens when you start scrolling, so we need to prevent it from staying
// in the afterDescendants mode if the EditText was focused
listView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With