android - In Scroll View Edit text has scroll both are worked but in edit text if we type no of lines user can't see edit text it is scroll to top. -


in layout have scroll view in scrollable edit text.both working using setontouchlistener.if touch edittext scroll , layout scroll interact. problem when user typing edittext moving top of layout , user can't see edit text field. at time user typing both scrolls working. think solution when user clicked on edit text need stop layout scroll.in way edit text visible user , not moving when user typing.but don't know how implement if know please me.

layout code:-

<scrollview xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     > <relativelayout     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"> <textview     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:gravity="center"     android:text="welcome register page"     android:textsize="20dp"     android:textstyle="bold"     android:id="@+id/title"     android:textcolor="@android:color/holo_blue_bright"/>      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_below="@+id/title"         android:layout_margintop="5dp"         android:orientation="vertical"         android:id="@+id/lin1"         android:background="@drawable/shape">      <textview          android:layout_width="match_parent"          android:layout_height="wrap_content"          android:text="personal details"          android:gravity="center"/>       <linearlayout           android:layout_width="match_parent"           android:layout_height="wrap_content"           android:layout_margintop="10dp"           android:orientation="horizontal">           <textview               android:layout_width="wrap_content"               android:layout_height="wrap_content"               android:text="first name :"/>           <edittext               android:layout_width="match_parent"               android:layout_height="wrap_content"               android:id="@+id/fname"               android:inputtype="textcapsentences"               android:imeoptions="actionnext"               android:layout_marginleft="5dp"/>       </linearlayout>         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_margintop="10dp"             android:orientation="horizontal">             <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="last name :"/>             <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/lname"                 android:inputtype="textcapsentences"                 android:imeoptions="actionnext"                 android:layout_marginleft="5dp"/>         </linearlayout>         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_margintop="10dp"             android:orientation="horizontal">             <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="phone no :"/>             <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/pno"                 android:inputtype="number"                 android:imeoptions="actionnext"                 android:layout_marginleft="5dp"/>         </linearlayout>     </linearlayout>     <linearlayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_below="@id/lin1"         android:id="@+id/lin2"         android:orientation="vertical"         android:layout_margintop="10dp"         android:background="@drawable/shape">         <textview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:text="address"             android:gravity="center"/>         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="horizontal">             <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="city/town :"/>             <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/city"                 android:inputtype="textcapsentences"                 android:imeoptions="actionnext"                 android:layout_marginleft="5dp"/>          </linearlayout>         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="horizontal">             <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="state :"/>             <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/state"                 android:inputtype="textcapsentences"                 android:imeoptions="actionnext"                 android:layout_marginleft="5dp"/>          </linearlayout>         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="horizontal">             <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="country :"/>             <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/country"                 android:inputtype="textcapsentences"                 android:imeoptions="actionnext"                 android:layout_marginleft="5dp"/>          </linearlayout>         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="horizontal">             <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="zip code :"/>             <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/zipcode"                 android:inputtype="number"                 android:imeoptions="actionnext"                 android:layout_marginleft="5dp"/>          </linearlayout>     </linearlayout>     <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:id="@+id/lin3"         android:layout_below="@id/lin2"         android:orientation="vertical"         android:layout_margintop="10dp">         <textview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:text="enter full address"             android:gravity="center"/>         <edittext             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:maxlines="10"             android:lines="10"             android:maxems="1000"             android:scrollbars="vertical"             android:layout_margintop="5dp"             android:id="@+id/address"             android:gravity="top"             android:background="@drawable/shape"/>     </linearlayout>     <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:id="@+id/lin4"         android:layout_below="@id/lin3"         android:orientation="vertical"         android:layout_margintop="10dp"         android:background="@drawable/shape">         <textview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:text="other details"             android:gravity="center"/>         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="horizontal">             <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="e-mail :"/>             <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/email"                 android:singleline="true"                 android:imeoptions="actiondone"                 android:layout_marginleft="5dp"/>          </linearlayout>         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="horizontal">             <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="date of birth :"/>             <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/dob"                 android:focusable="false"                 android:imeoptions="actionnone"                 android:layout_marginleft="5dp"/>          </linearlayout>     </linearlayout>     <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:id="@+id/lin5"         android:layout_below="@id/lin4"         android:orientation="vertical"         android:layout_margintop="10dp"         android:background="@drawable/shape">         <textview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:text="other details"             android:gravity="center"/>         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="horizontal">             <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="e-mail :"/>             <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/email_dum"                 android:singleline="true"                 android:imeoptions="actiondone"                 android:layout_marginleft="5dp"/>          </linearlayout>         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="horizontal">             <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="date of birth :"/>             <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/dob_dum"                 android:focusable="false"                 android:imeoptions="actionnone"                 android:layout_marginleft="5dp"/>          </linearlayout>     </linearlayout>     <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:id="@+id/lin6"         android:layout_below="@id/lin5"         android:orientation="vertical"         android:layout_margintop="10dp"         android:background="@drawable/shape">         <textview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:text="other details"             android:gravity="center"/>         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="horizontal">             <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="e-mail :"/>             <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/email_dum1"                 android:singleline="true"                 android:imeoptions="actiondone"                 android:layout_marginleft="5dp"/>          </linearlayout>         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:orientation="horizontal">             <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="date of birth :"/>             <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/dob_dum1"                 android:focusable="false"                 android:imeoptions="actionnone"                 android:layout_marginleft="5dp"/>          </linearlayout>     </linearlayout>      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="horizontal"         android:layout_below="@id/lin6"         android:gravity="center">         <button             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="submit"             android:id="@+id/submit"/>         <button             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/clear"             android:text="clear"             android:layout_marginleft="5dp"/>      </linearlayout> </relativelayout> </scrollview> 

main activity_code:-

public class mainactivity extends appcompatactivity {      edittext first_name,last_name,phone_no,city,state,country,zip_code,full_address,email,dob;      button submit,clear;     private int year;     private int month;     private int day;     private calendar cal;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          first_name=(edittext)findviewbyid(r.id.fname);         last_name=(edittext)findviewbyid(r.id.lname);         phone_no=(edittext)findviewbyid(r.id.pno);         city=(edittext)findviewbyid(r.id.city);         state=(edittext)findviewbyid(r.id.state);         zip_code=(edittext)findviewbyid(r.id.zipcode);         country=(edittext)findviewbyid(r.id.country);         full_address=(edittext)findviewbyid(r.id.address);         email=(edittext)findviewbyid(r.id.email);         dob=(edittext)findviewbyid(r.id.dob);          submit=(button) findviewbyid(r.id.submit);         clear=(button) findviewbyid(r.id.clear);          cal = calendar.getinstance();         day = cal.get(calendar.day_of_month);         month = cal.get(calendar.month);         year = cal.get(calendar.year);           submit.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                  intent intent=new intent(mainactivity.this,result.class);                  bundle bundle=new bundle();                 bundle.putstring("first_name",first_name.gettext().tostring());                 bundle.putstring("last_name",last_name.gettext().tostring());                 bundle.putstring("phone_no",phone_no.gettext().tostring());                 bundle.putstring("city",city.gettext().tostring());                 bundle.putstring("state",state.gettext().tostring());                 bundle.putstring("country",country.gettext().tostring());                 bundle.putstring("zip_code",zip_code.gettext().tostring());                 bundle.putstring("full_address",full_address.gettext().tostring());                 bundle.putstring("email",email.gettext().tostring());                 bundle.putstring("dob",dob.gettext().tostring() );                  intent.putextras(bundle);                  startactivity(intent);             }         });          clear.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                  first_name.settext("");                 last_name.settext("");                 phone_no.settext("");                 city.settext("");                 state.settext("");                 country.settext("");                 zip_code.settext("");                 full_address.settext("");                 email.settext("");                 dob.settext("");              }         });          dob.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 datedialog();             }         });         full_address.setontouchlistener(new edittext.ontouchlistener() {             @override             public boolean ontouch(view v, motionevent event) {                 int action = event.getaction();                 switch (action) {                     case motionevent.action_down:                         // disallow scrollview intercept touch events.                         v.getparent().requestdisallowintercepttouchevent(true);                         break;                      case motionevent.action_up:                         // allow scrollview intercept touch events.                         v.getparent().requestdisallowintercepttouchevent(false);                         break;                 }                  // handle listview touch events.                 v.ontouchevent(event);                 return true;             }         });     }      private void datedialog() {         datepickerdialog.ondatesetlistener listener=new datepickerdialog.ondatesetlistener() {              @override             public void ondateset(datepicker view, int year, int monthofyear, int dayofmonth)             {                  dob.settext(dayofmonth+"/"+monthofyear+"/"+year);              }};           datepickerdialog dpdialog=new datepickerdialog(this, listener, year, month, day);         dpdialog.show();     } } 

u can check code.

thanks in advance.

you can make use of linear layout parent class instead of relative layout. position of edit text should fixed weight and, may visible while typing.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -