【问题标题】:In android, how to drop down edit text fields when a button is pressed在android中,按下按钮时如何下拉编辑文本字段
【发布时间】:2014-01-13 21:02:32
【问题描述】:

我有一个按钮Add new address,当按下它时,我想显示EditText 字段以收集新地址详细信息。是否有任何布局可以做到这一点。或者当 Button 未按下时隐藏文本字段,这是唯一的方法吗?

【问题讨论】:

标签: android android-edittext


【解决方案1】:

在布局中定义编辑框如下 -

<LinearLayout 
        android:id="@+id/exp_linear_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
         <EditText
        android:id="@+id/exp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginTop="10dp"

       />

</LinearLayout>

现在使用布局 id 来获取如下视图。

LinearLayout l=(LinearLayout)findViewById(R.id.exp_linear_layout);

只需切换按钮点击事件的可见性 -

l.setVisibility(View.GONE) and vice versa.

希望对你有帮助。

【讨论】:

    【解决方案2】:

    没有内置的框架可以做到这一点。您可以通过将View.SetVisibility() 设置为可见或消失来执行此操作。最初按钮是可见的,但文本字段是不可见的。当用户单击按钮时,您可以将此按钮的可见性设置为不可见或在文本字段中消失和可见。

    【讨论】:

      猜你喜欢
      • 2011-11-09
      • 1970-01-01
      • 2020-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-10
      • 1970-01-01
      相关资源
      最近更新 更多