我正在尝试在我的应用程序中使用AutoCompleteTextView而不是EditText。但是该应用程序崩溃NullPointException。我对android和java还是比较陌生。因此,请帮助我声明和使用它。
我的代码-
自定义警报XML代码-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Enter Id"
android:id="@+id/textView"
android:textStyle="bold"
android:textColor="#000000"
android:layout_gravity="center_horizontal" />
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/enterId"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
Run Code Online (Sandbox Code Playgroud)
警报对话框代码-
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"};
protected void showInputDialog() {
LayoutInflater layoutInflater = LayoutInflater.from(MainActivity.this);
View promptView = layoutInflater.inflate(R.layout.originalalert, null);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
alertDialogBuilder.setView(promptView);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
final AutoCompleteTextView textView …Run Code Online (Sandbox Code Playgroud)