How to dynamically add edittext to android

前端 未结 1 1018
执笔经年
执笔经年 2021-01-07 09:00

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

相关标签:
1条回答
  • 2021-01-07 09:25

    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);
    
    0 讨论(0)
提交回复
热议问题