[英]How to add more EditText in xml layout at run time in Android?
I am making an android app which on pressing add button adds 2 TextViews at the bottom of other TextViews.我正在制作一个 android 应用程序,按下添加按钮会在其他 TextViews 的底部添加 2 个 TextViews。 I have made a layout on xml.我在 xml 上做了一个布局。 Now the problem is how to point out that layout in java part and then adding TextViews at the run time.现在的问题是如何在java部分指出该布局,然后在运行时添加TextViews。
This answer assumed that you are using LinearLayout as a layout...!这个答案假设您使用LinearLayout作为布局...!
Use this code in your activity,在您的活动中使用此代码,
LinearLayout layout = (LinearLayout) findViewById(R.id.your_layout_id);
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
TextView tv=new TextView(this);
tv.setLayoutParams(lparams);
tv.setText("test");
layout.addView(tv);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.