简体   繁体   English

如何将编辑文本动态添加到Xamarin Android

[英]How do I Add an EditText Dynamically to xamarin android

XAMARIN ANDROID DYNAMIC CLICK: I want the spinner, edit text and positive button to be placed side by side such that when the button is clicked by any user, it regenrates the same content (spinner, edittext and a negative button) and for every click on the positive button the same thing happens while for every click on the negative button, the content where the negative button is will be removed. XAMARIN ANDROID DYNAMIC CLICK:我希望微调器,编辑文本和肯定按钮并排放置,以便当任何用户单击该按钮时,它会重新生成相同的内容(微调器,edittext和否定按钮)在肯定按钮上会发生同样的事情,而每次在否定按钮上单击都会删除否定按钮所在的内容。

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layoutTeste"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Spinner
        android:id="@+id/spn"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@id/et" />
    <EditText
        android:id="@+id/et"
        android:layout_height="wrap_content"
        android:layout_width="200dp"
        android:hint="Enter a Value"
        android:layout_gravity="center"
        android:layout_marginLeft="70dp" />
    <Button
        android:id="@+id/btnDisplay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btnDisplay"
        android:layout_alignParentRight="true"
        android:layout_alignBaseline="@id/et" />
</RelativeLayout>

Dynamically you can create view in xamarin android programmatically for your need. 您可以根据需要动态地在xamarin android中创建视图。

For Example 例如

LinearLayout LL = FindViewById<LinearLayout(Resource.Id.Linear_MS); //root layout
var param = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
        param.SetMargins(20, 20, 20, 10);
var et = new EditText(this);
LL.AddView(et, param);

In Xml side by side design use this. 在Xml并排设计中使用它。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layoutTeste"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:id="@+id/ll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="3">
    <Spinner
        android:id="@+id/spn"
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:layout_alignParentLeft="true"
        android:layout_weight="1"
        android:layout_alignTop="@id/et" />
    <EditText
        android:id="@+id/et"
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:hint="Enter a Value"
        android:layout_gravity="center"
        android:layout_weight="1"
         />
    <Button
        android:id="@+id/btnDisplay"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/btnDisplay"
        android:layout_weight="1"
      />
    </LinearLayout>
</RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM