How to dynamically add edittext to android

纵然是瞬间 提交于 2019-12-03 22:38:30

问题


I want to add edittext dynamically to the android display. I want to make something like in the android contacts where you can dynamically add fields and remove them if you dont need them.

Thank you for your help


回答1:


See Everything dynamically

TextView tv=new TextView(this);
        tv.setText("TaskID");
        TextView tv1=new TextView(this);
        task=new EditText(this);
        task.setMaxWidth(100);
        task.setMinHeight(100);
        tv1.setText("Task");
        id=new EditText(this);
        id.setMaxHeight(10);
        TextView tv2=new TextView(this);
        name=new EditText(this);

        name.setMaxHeight(1);
        tv2.setText("Name");


        LinearLayout l=new LinearLayout(this);
        l.setOrientation(LinearLayout.VERTICAL);
        l.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));  
         setContentView(l);


         l.addView(tv);
         l.addView(id);

        l.addView(tv1);
        l.addView(task);
        l.addView(tv2);


来源:https://stackoverflow.com/questions/7122420/how-to-dynamically-add-edittext-to-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!