如何从 alertDialog.setView(R.layout.some_layout) 获取 EditText 的值

How to get the value of EditText from alertDialog.setView(R.layout.some_layout)

我已将自定义布局资源文件设置为警报对话框的视图,但我无法从布局中的视图中获取/获取值。有人可以指出我在这里做错了什么吗?还是有其他方法可以做到这一点?

some_layout.xml

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <EditText android:inputType="textAutoComplete"
        android:textSize="20sp"
        android:id="@+id/title"
        android:scrollHorizontally="true"
        android:layout_height="70dp"
        android:hint="Title / Username"
        android:layout_width="250dp"
        android:layout_gravity="center"
        android:autofillHints="username" />
    <EditText android:inputType="textVisiblePassword"
        android:textSize="20sp"
        android:id="@+id/password"
        android:scrollHorizontally="true"
        android:layout_height="70dp"
        android:hint="Password"
        android:layout_width="250dp"
        android:layout_gravity="center"
        android:autofillHints="password" />

</LinearLayout>

代码:

AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setTitle("Credentials");
alertDialog.setView(R.layout.some_layout);
EditText title = (TextView) some_layout.findViewById(R.id.title);

错误:(EditText 定义中的 'some_layout' 以红色突出显示,并且有此消息)

Cannot resolve symbol 'password_item_dialog'

我自己解决了

LayoutInflater layoutInflater = LayoutInflater.from(context);
final View alertView = layoutInflater.inflate(R.layout.some_layout, null);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setView(alertView);
EditText title = (EditText) alertView.findViewById(R.id.title);