android - Dynamically added EditText is not visible when created -


i have been reading how dynamically add edittext field linear layout, every-time user clicks textview (which has onclick listener attached).

i have had mild success - know edittext field being created because when button clicked, other elements move if being added screen.

my problem edittext aren't visible , haven't clue why is, appreciated.

the app isn't crashing nothing add in terms of stacktrace , log, far app concerned, being created.

<?xml version="1.0" encoding="utf-8"?>  <scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fillviewport="true">  <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/linearlayout"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="@color/facebookblue"     android:orientation="vertical"     android:weightsum="1"     tools:context="com.test.practise.addteammembers">       <android.support.design.widget.textinputedittext         android:id="@+id/tv_teamnames"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center"         android:gravity="center"         android:text="@string/teamname"         android:textcolor="@android:color/background_light"         android:textcolorlink="@android:color/background_light"         android:textsize="30sp"         android:textstyle="bold" />       <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_weight="0.26"         android:orientation="vertical"         android:weightsum="1">          <textview             android:id="@+id/textview3"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_gravity="center"             android:layout_weight="0.47"             android:gravity="center"             android:text="enter player names below!"             android:textcolor="@android:color/background_light"             android:textsize="24sp" />      </linearlayout>       <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_weight="0.16"         android:orientation="vertical"         android:weightsum="1">          <edittext              android:id="@+id/et_team_name1"             android:layout_width="232dp"             android:layout_height="37dp"             android:layout_centervertical="true"             android:layout_gravity="center"             android:background="@android:color/background_light"             android:ems="10"             android:hint="team name"             android:imeoptions="actiondone"             android:inputtype="text"             android:paddingleft="70dp"             android:singleline="true"             tools:layout_editor_absolutex="76dp"             tools:layout_editor_absolutey="188dp" />      </linearlayout>      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_weight="0.16"         android:orientation="vertical"         android:weightsum="1">          <edittext             android:id="@+id/et_team_name2"             android:layout_width="232dp"             android:layout_height="37dp"             android:layout_centerhorizontal="true"             android:layout_gravity="center"             android:background="@android:color/background_light"             android:ems="10"             android:hint="team name"             android:imeoptions="actiondone"             android:inputtype="text"             android:paddingleft="70dp"             android:singleline="true"             tools:layout_editor_absolutex="76dp"             tools:layout_editor_absolutey="188dp" />      </linearlayout>      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_weight="0.16"         android:orientation="vertical"         android:weightsum="1">          <edittext             android:id="@+id/et_team_name3"             android:layout_width="232dp"             android:layout_height="37dp"             android:layout_gravity="center"             android:background="@android:color/background_light"             android:ems="10"             android:hint="team name"             android:imeoptions="actiondone"             android:inputtype="text"             android:paddingleft="70dp"             android:singleline="true"             tools:layout_editor_absolutex="76dp"             tools:layout_editor_absolutey="188dp" />      </linearlayout>      <linearlayout         android:id="@+id/edittextgrouplayout"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="vertical"          >     </linearlayout>      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_weight="0.07"         android:orientation="vertical"         android:weightsum="1">          <textview             android:id="@+id/tv_add_name"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_gravity="center"             android:gravity="center"             android:text="+ add name"             android:textcolor="@android:color/background_light"             android:textsize="16dp" />      </linearlayout>       <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="vertical"         android:weightsum="1">          <button             android:id="@+id/button"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_gravity="center"             android:background="@color/facebookblue"             android:gravity="center"             android:text="ready join!"             android:textcolor="@android:color/background_light" />       </linearlayout>        </linearlayout>       </scrollview> 

below addteammembers class calls above xml

 public class addteammembers extends fragment implements   view.onclicklistener   {  private sharedpreferences pref; private textview tv_teamnames, tv_add_name; private linearlayout mlayout;       //the below method must overridden in order implement fragment -    changes lifecycle method    @override    public view oncreateview(layoutinflater inflater, viewgroup container,     bundle savedinstancestate) {       view view = inflater.inflate(r.layout.activity_add_team_members,      container, false);     initviews(view);     return view;      }       @override     public void onviewcreated(view view, bundle savedinstancestate) {     // 0, sets shared pref mode private     pref = getactivity().getpreferences(0);     tv_teamnames.settext(pref.getstring(constants.team_name, ""));     }      private void initviews(view view) {      tv_teamnames = (textview) view.findviewbyid(r.id.tv_teamnames);     tv_add_name = (textview) view.findviewbyid(r.id.tv_add_name);      mlayout = (linearlayout) view.findviewbyid(r.id.edittextgrouplayout);      tv_add_name.setonclicklistener(this);      }    @override    public void onclick(view view) {      switch (view.getid()) {          case r.id.tv_add_name:             createedittextview();             break;         }     }     @targetapi(build.version_codes.m)    public void createedittextview() {      try{          //dynamically create new edittext when user clicks add            name         //target user using api 22 , above (lollipop , above)         edittext edittextview = null;         if (android.os.build.version.sdk_int >=          android.os.build.version_codes.m) {             edittextview = new edittext(getcontext());         }else{             toast.maketext(getactivity(), "app not supported on          device",                     toast.length_long).show();         }         edittextview.setgravity(gravity.center);          linearlayout.layoutparams params = new          linearlayout.layoutparams(linearlayout.layoutparams.wrap_content,                 linearlayout.layoutparams.wrap_content, 1);          edittextview.setlayoutparams(params);          mlayout.addview(edittextview);            }catch(exception e){         log.d(tag, "failed create new edit text");     }    }    }  [![before button clicked][1]][1] [![i have clicked 2 add 3 edittext here make obvious whats happening] [2]][2]   [1]: https://i.stack.imgur.com/dgopd.png [2]: https://i.stack.imgur.com/3lwcy.png 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -