在弹出窗口上编辑文本

发布于 2024-10-01 12:30:20 字数 121 浏览 0 评论 0原文

我正在使用 Java 在 Android 2.2 上进行开发。 我将 editText 放在 PopupWindow 上,但它不起作用。 它的作用就像禁用的编辑文本,单击编辑文本不会显示软键盘。 如何在弹出窗口上添加编辑文本?

I am developing on Android 2.2 using Java.
I put an editText on a PopupWindow and it's not working.
It acts like a disabled edit text, clicking on the edit text won't show the soft keyboard.
How can I add an edit text on a popupWindow?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

失退 2024-10-08 12:30:21

我已经解决了这样的问题:我放置了 popupWindow.setFocusable(true); 现在它可以工作了。弹出窗口上的编辑文本似乎没有焦点,因为弹出窗口没有焦点。

I have resolved the problem like this: I put the popupWindow.setFocusable(true); and now it's working. It seems that the edit text which was on a pop window didn't have focus because the popup window didn't have focus.

岁月无声 2024-10-08 12:30:21

从任何侦听器调用此代码

private void popUpEditText() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Comments");

        final EditText input = new EditText(this);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT);
        input.setLayoutParams(lp);
        builder.setView(input);

        // Set up the buttons
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

             // do something here on OK 

            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.show();

    }

call this code from any listener

private void popUpEditText() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Comments");

        final EditText input = new EditText(this);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT);
        input.setLayoutParams(lp);
        builder.setView(input);

        // Set up the buttons
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

             // do something here on OK 

            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.show();

    }
萌面超妹 2024-10-08 12:30:21

EditText 是否确实将 android:editable 属性设置为 true ?如果它是假的,它将按照您的描述被禁用。

Does the EditText definitely have the android:editable property set to true? If it's false it will be disabled as you describe.

挽清梦 2024-10-08 12:30:21
popWindow.setFocusable(true);
popWindow.update();

它会起作用的。

popWindow.setFocusable(true);
popWindow.update();

It will work.

清醇 2024-10-08 12:30:20

试试:

AlertDialog.Builder alert = new AlertDialog.Builder(this);

alert.setTitle("Title");
alert.setMessage("Message");

// Set an EditText view to get user input 
final EditText input = new EditText(this);
alert.setView(input);

alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {

  // Do something with value!
  }
});

alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int whichButton) {
    // Canceled.
  }
});

alert.show();

Just try:

AlertDialog.Builder alert = new AlertDialog.Builder(this);

alert.setTitle("Title");
alert.setMessage("Message");

// Set an EditText view to get user input 
final EditText input = new EditText(this);
alert.setView(input);

alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {

  // Do something with value!
  }
});

alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int whichButton) {
    // Canceled.
  }
});

alert.show();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文