Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在我的Android应用程序中基于按钮点击创建输入字段?_Java_Android_Xml_Android Layout_Android Studio - Fatal编程技术网

Java 如何在我的Android应用程序中基于按钮点击创建输入字段?

Java 如何在我的Android应用程序中基于按钮点击创建输入字段?,java,android,xml,android-layout,android-studio,Java,Android,Xml,Android Layout,Android Studio,这就是我的XML当前的样子: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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:layou

这就是我的XML当前的样子:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Typ hier in welk cijfer u wilt komen te staan:"
    android:textSize="30sp"
    android:gravity="center"
    android:paddingTop="10dp"
    android:textStyle="bold"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <EditText
        android:id="@+id/EditText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="Vul hier het cijfer in"
        android:paddingTop="100dp"
        android:background="@null"
        android:paddingLeft="30dp"
        android:maxLength="4"
        android:inputType="numberDecimal"/>

    <Button
        android:id="@+id/Button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Volgende"
        android:layout_marginLeft="75dp"/>
</LinearLayout>

我想在点击按钮时在我的应用程序界面中添加10个EditText输入字段。有人能告诉我怎么做吗?谢谢。

试试这个

LinearLayout mLayout = (LinearLayout) findViewById(R.id.linearLayout);
Button mButton = (Button) findViewById(R.id.my_button);
mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText editText = new EditText(TmyContext);
            editText.setLayoutParams(new 
LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 
LinearLayout.LayoutParams.WRAP_CONTENT));
            mLayout.addView(editText);
        }
    });
你好看看这个:可能是重复的