android - How to invoke onClick and onLongClick of EditText from RelativeLayout -


i'm creating compose screen app. have scrollview contains relativeview in turn contains 2 things: edittext user types message, , imageview visibility toggled on , off depending on whether image attached status or not. here's part of layout xml.

<!-- @dimen/biggap = 8dp --> <scrollview android:id="@+id/parentscrollview"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:fillviewport="true"     android:layout_margintop="@dimen/biggap"     android:layout_marginright="@dimen/biggap"     android:layout_marginleft="@dimen/biggap"     android:layout_marginbottom="@dimen/biggap"     android:layout_above="@+id/footer"     android:background="#006400"     > <!-- green background color -->      <relativelayout android:id="@+id/parentlinearlayout"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:background="#ffd700"> <!-- yellow background color -->          <edittext android:id="@+id/posttext"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:background="#dddddd"             android:inputtype="textmultiline"             android:gravity="top|left"             /> <!-- gray background color -->          <imageview android:id="@+id/postimage"             android:layout_width="@dimen/thumbnailsize"             android:layout_height="@dimen/thumbnailsize"             android:visibility="gone"             android:layout_below="@id/posttext"             />     </relativelayout> </scrollview> 

because edittext's height wrap_content, whole thing starts off single line of gray background (the edittext) on top of yellow background (the relativelayout, covers green background of scrollview). however, i'll later change views' backgrounds white (to make them single component) , counter-intuitive user able tap single line of edittext make keyboard pop up.

enter image description here

what want redirect click , long click actions of relativelayout click , long click actions of edittext, code below doesn't work. help?

final edittext edittext = (edittext) findviewbyid(r.id.posttext); relativelayout rl = (relativelayout) findviewbyid(r.id.parentlinearlayout); rl.setonclicklistener(new view.onclicklistener() {     @override     public void onclick(view v) {         logger.d("onclick invoked!");         edittext.performclick();     } }); rl.setonlongclicklistener(new view.onlongclicklistener() {     @override     public boolean onlongclick(view v) {         logger.d("onlongclick invoked!");         return edittext.performlongclick();     } }); 

my intention here when relativelayout clicked, keyboard pops (as when done edittext) , when long-pressed, display cut/copy/paste/text selection options (same behavior edittext).

from description, want open keyboard. title question suggests solution, not actual problem.

call click listener (or when show page):

  ((inputmethodmanager) myactivity             .getsystemservice(context.input_method_service))             .togglesoftinput(inputmethodmanager.show_forced,                     inputmethodmanager.hide_implicit_only); 

edit: must call edittext.requestfocus(); (@phil right), experience it's not enough open keyboard, you'll need ugly code above.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -