简体   繁体   English

如何在Android运行时在xml布局中添加更多EditText?

[英]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.

相关问题 如何在一个editText Android中添加更多值? - How to add more values in one editText Android? Android-版式xml中EditText大小的问题 - Android - Issue with size of EditText in Layout xml Android在线性布局中动态添加EditText - Android dynamically add EditText in Linear Layout 如何使用Android Studio在单个EditText中添加用户随机选择的两个或多个数字? - how do you add two or more numbers selected randomly by the user in a single EditText using android studio? 如何在运行时设置EditText的文本值? - How to set the text value of EditText at run time? 在Android布局XML中的EditText元素之前放置TextView导致EditText不显示 - Placing a TextView before EditText element in Android layout XML causes EditText not to show 如何使多个Android AsyncTask同时运行? - How to make more than one Android AsyncTask run at the same time? 如何在没有 layout.xml 的情况下使用 ImageView 和 EditText 显示 AlertDialog? - How to display AlertDialog with ImageView and EditText without layout.xml? 如何在公共界面上获取 EditText (Layout.xml) 的值? - How to get the Value of an EditText (Layout.xml) on public interface? 如何限制Android中EditText的输入时间 - How to restrict to input time for edittext in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM