Reputation: 7932
I have a android view layout structure as follows
<RelativeLayout>
<TextView>
<EditText>
</RelativeLayout>
The EditText, due to my limited layout skills, is sized as wrap_content and is significantly smaller than the parent RelativeLayout.
But when user touches on RelativeLayout, I would like the UI to effectively behave as if user just focused on the EditText instead.
It doesn't matter to me if cursor starts in the front, middle, or end. (Preferably at the end).
Is this something that i can achieve in the code or on the layout?
Thanks!
Upvotes: 1
Views: 194
Reputation: 6793
What you can do is to call the editText's onClick
in the onClick
method of the relative layout. This way all clicks on the relativeLayout
go to the editText
.
This should work see answer:
relativeLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editText.setFocusableInTouchMode(true);
editText.requestFocus();
//needed for some older devices.
InputMethodManager inputMethodManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}
});
I would do this programatically (in code), because it does not handle how the views look, but how they behave. Therefore, say in MVC, it belongs in the controller.
Upvotes: 1