gpt4 book ai didi

android - android中自定义对话框上的可滚动EditText

转载 作者:行者123 更新时间:2023-11-29 22:27:29 25 4
gpt4 key购买 nike

我需要在自定义对话框上放置带有垂直滚动条的 EditText 框。即当我在 edittext 上输入多于一行时,它应该被滚动。这里我在 xml 上使用了 android: scrollable="vertical"。它工作正常。当我使用两个编辑文本框时,当我先按回车键时,光标将移动到第二个编辑文本框。有什么错误吗?

我的代码...

EditText edit1,edit,edit0;
Button ok;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);

final Dialog dialog = new Dialog(summaact.this);
dialog.setContentView(R.layout.main);
edit0=(EditText)dialog.findViewById(R.id.edit0);
edit=(EditText)dialog.findViewById(R.id.edit);
edit1=(EditText)dialog.findViewById(R.id.edit1);

edit0.setInputType(InputType.TYPE_NULL);
edit.setInputType(InputType.TYPE_NULL);
edit1.setInputType(InputType.TYPE_NULL);

ok=(Button)dialog.findViewById(R.id.ok);
dialog.setTitle("Content Management page");
dialog.setCancelable(true);
ok.setOnClickListener(new OnClickListener(){

public void onClick(View v){
String str0=edit0.getText().toString();
String str=edit1.getText().toString();
String str1=edit.getText().toString();

Toast.makeText(summaact.this,str0,Toast.LENGTH_SHORT).show();
Toast.makeText(summaact.this,str,Toast.LENGTH_SHORT).show();
Toast.makeText(summaact.this,str1,Toast.LENGTH_SHORT).show();


dialog.dismiss();
}
});

dialog.show();

}

我的 xml...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="@+id/edit0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"

/>
<EditText
android:id="@+id/edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"

/>

<EditText
android:id="@+id/edit1"
android:layout_width="fill_parent"
android:layout_height="100px"
android:scrollbars="vertical"


/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ok"
android:text="OK"/>

</LinearLayout>

最佳答案

新答案:

尝试使用:

android:inputType="textMultiLine"

在编辑文本中

编辑:

我做了一个例子,它适用于 textMultiline:

@Override
protected void onResume() {
super.onResume();

AlertDialog.Builder b = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.main, null);
b.setView(view);
b.setTitle("Content Management page");

b.create().show();
}

布局相同,除了一个 EditText:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="@+id/edit0"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/edit1"
android:layout_width="fill_parent"
android:gravity="top|left"
android:layout_height="100dp"
android:scrollbars="vertical"
android:inputType="textMultiLine" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ok"
android:text="OK" />

</LinearLayout>

enter image description here

你哪里有问题?

关于android - android中自定义对话框上的可滚动EditText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5419067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com