【问题标题】:best way to take text input up to 2000 character android applicaiton将文本输入最多 2000 个字符的 android 应用程序的最佳方法
【发布时间】:2015-10-11 09:43:57
【问题描述】:

我的应用程序应该能够显示一些对话框或活动,以便从用户那里获取文本输入。带有确定和取消按钮

我尝试了两种方法 1. 具有自定义布局的警报对话框,即编辑文本、确定和取消按钮 但是一旦用户点击确定,onClick() 事件只接受最终字符串。并且从 Main 活动调用警报对话框,但在 Utils 类中编写的代码说 Utils.showDialog()。

一旦对话框获取数据,我需要将编辑文本字符串传递回调用 util.showdialog() 的 MainActivity。

其他方法 2.从 MainActivity 开始新的活动,编辑文本,确定并取消布局。一旦用户点击确定,在活动中,我就会得到字符串并处理它。布局是在确定和取消按钮下方的编辑文本。

其中一个问题是,我将字符数限制为 2000,当我输入的文本超过手机屏幕(比如 5 英寸)时,OK 取消按钮正在按下并且无法访问 OK 和 CANCEL 按钮。

如果我需要使用第二种方法,我应该能够修复底部的确定和取消按钮,并且上面的编辑文本应该能够上下移动。

我怎样才能做到这一点,哪一个合适?

【问题讨论】:

  • 您可以通过编程方式修复对话框大小:alertDialog.getWindow().setLayout(600, 400); //控制宽度和高度。

标签: android android-activity alert


【解决方案1】:

第二种方法的布局应该是这样的

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:maxLength="2000" />
    </ScrollView>

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

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="OK" />

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Cancel" />

    </LinearLayout>

</RelativeLayout>

【讨论】:

  • 我尝试了这种布局,但是当数据输入超出屏幕限制时,确定和取消按钮会消失并且不可见。我希望两个按钮都应该在底部可见,编辑文本视图应该能够滚动。上面的编辑文本是可滚动的,但按钮在输入的几行之后停止可见。
  • @Sudarshansridhar 将android:id 属性添加到您的LinearLayout,将其命名为linearLayoutId,然后将以下行添加到ScrollView - android:layout_above="@+id/linearLayoutId"
猜你喜欢
  • 1970-01-01
  • 2012-03-20
  • 1970-01-01
  • 2010-09-10
  • 2013-06-03
  • 1970-01-01
  • 2012-03-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多