android - EditText onClick not working in fragment -
i have set onclick property of edittext located in fragment:
<edittext android:id="@+id/edittext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputtype="none" android:maxlines="1" android:singleline="true" android:layout_margintop="16dp" android:focusable="false" android:longclickable="false" android:clickable="true" android:onclick="dosomething" android:cursorvisible="false" android:editable="false">
then in fragment class have:
public void dosomething(view view) { //show dialogfragment... }
but method dosomething
grayed out , warning 'method dosomething never used'.
note: code in activity , working fine.
is there way handle onclick in fragments?
first initialize edittext
instance in top of fragment
edittext et;
then in oncreateview()
add:
etemployee=(edittext)rootview.findviewbyid(r.id.edittext1);
then implement onclicklistener()
et.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { //what ever need goes here } });
note: in fragments have refer inflatedview
able access edittext
in case rootview.
also code using doesn't work becouse here using fragments , using onclick
attribute in xml make able use in mainactivity
contain fragment
.
hope help.
Comments
Post a Comment