我有 2 个 AutoCompleteTextview 如何填充两者
i have 2 AutoCompleteTextview how to populate both
我制作了 3 个 AutoCompleteTextview,但是当我填充它时,只有第一个被填充,另一个不工作。
注意:我正在使用自定义 AutoCompleteTextview 来解决 1 个问题的阈值。
我的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activities.ActivityProjectInfo2Preference">
<!--toolbar-->
<include layout="@layout/toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/dimens_10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginTop="@dimen/_16sdp"
android:layout_marginStart="@dimen/_16sdp"
android:text="Preferences"
android:textColor="@color/colorBlack"
android:textSize="@dimen/_18ssp"
android:textStyle="bold" />
<!--User of Room-->
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dimens_16sp"
android:paddingStart="@dimen/_14sdp"
android:hint="User of Room">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/user_of_room"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<!--style preference-->
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_16sdp"
android:paddingStart="@dimen/_14sdp"
android:hint="Style Preferences">
<ctdworld.com.eid.helper.InstantAutoComplete
android:id="@+id/activity_quiz_project_info_2_style_pref_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_16sdp"
android:paddingStart="@dimen/_14sdp"
android:hint="Color Preferences">
<ctdworld.com.eid.helper.InstantAutoComplete
android:id="@+id/activity_quiz_project_info_2_color_pref_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_16sdp"
android:paddingStart="@dimen/_14sdp"
android:hint="Color Preferences">
<ctdworld.com.eid.helper.InstantAutoComplete
android:id="@+id/activity_quiz_project_info_2_finish_pref_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
我的java代码:
String[] styleArray = getResources().getStringArray(R.array.entries_style_preference);
ArrayAdapter styleAdapter = new ArrayAdapter(this,
R.layout.dropdown_menu_popup_item,
styleArray);
styleAdapter.getFilter();
mStylePrefSpinner.setAdapter(styleAdapter);
String[] colorArray = getResources().getStringArray(R.array.entries_colors_preference);
ArrayAdapter colorAdapter = new ArrayAdapter(this,
R.layout.dropdown_menu_popup_item,
colorArray);
colorAdapter.getFilter();
mStylePrefSpinner.setAdapter(colorAdapter);
String[] finishArray = getResources().getStringArray(R.array.entries_finish_preference);
ArrayAdapter finishAdapter = new ArrayAdapter(this,
R.layout.dropdown_menu_popup_item,
finishArray);
finishAdapter.getFilter();
mStylePrefSpinner.setAdapter(finishAdapter);
我一个一个地尝试然后它开始工作,但是当我为所有三个编写代码时,只有一个可以工作。
您始终将适配器分配给同一个绑定 属性 mStylePrefSpinner
:
...
mStylePrefSpinner.setAdapter(styleAdapter);
...
mStylePrefSpinner.setAdapter(colorAdapter);
...
mStylePrefSpinner.setAdapter(finishAdapter);
您应该将其设置为每个绑定 属性。假设它们是 mStylePrefSpinner
、mStyleColorSpinner
& mStyleFinishSpinner
:
...
mStylePrefSpinner.setAdapter(styleAdapter);
...
mStyleColorSpinner.setAdapter(colorAdapter);
...
mStyleFinishSpinner.setAdapter(finishAdapter);
我制作了 3 个 AutoCompleteTextview,但是当我填充它时,只有第一个被填充,另一个不工作。
注意:我正在使用自定义 AutoCompleteTextview 来解决 1 个问题的阈值。
我的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activities.ActivityProjectInfo2Preference">
<!--toolbar-->
<include layout="@layout/toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/dimens_10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginTop="@dimen/_16sdp"
android:layout_marginStart="@dimen/_16sdp"
android:text="Preferences"
android:textColor="@color/colorBlack"
android:textSize="@dimen/_18ssp"
android:textStyle="bold" />
<!--User of Room-->
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dimens_16sp"
android:paddingStart="@dimen/_14sdp"
android:hint="User of Room">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/user_of_room"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<!--style preference-->
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_16sdp"
android:paddingStart="@dimen/_14sdp"
android:hint="Style Preferences">
<ctdworld.com.eid.helper.InstantAutoComplete
android:id="@+id/activity_quiz_project_info_2_style_pref_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_16sdp"
android:paddingStart="@dimen/_14sdp"
android:hint="Color Preferences">
<ctdworld.com.eid.helper.InstantAutoComplete
android:id="@+id/activity_quiz_project_info_2_color_pref_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_16sdp"
android:paddingStart="@dimen/_14sdp"
android:hint="Color Preferences">
<ctdworld.com.eid.helper.InstantAutoComplete
android:id="@+id/activity_quiz_project_info_2_finish_pref_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
我的java代码:
String[] styleArray = getResources().getStringArray(R.array.entries_style_preference);
ArrayAdapter styleAdapter = new ArrayAdapter(this,
R.layout.dropdown_menu_popup_item,
styleArray);
styleAdapter.getFilter();
mStylePrefSpinner.setAdapter(styleAdapter);
String[] colorArray = getResources().getStringArray(R.array.entries_colors_preference);
ArrayAdapter colorAdapter = new ArrayAdapter(this,
R.layout.dropdown_menu_popup_item,
colorArray);
colorAdapter.getFilter();
mStylePrefSpinner.setAdapter(colorAdapter);
String[] finishArray = getResources().getStringArray(R.array.entries_finish_preference);
ArrayAdapter finishAdapter = new ArrayAdapter(this,
R.layout.dropdown_menu_popup_item,
finishArray);
finishAdapter.getFilter();
mStylePrefSpinner.setAdapter(finishAdapter);
我一个一个地尝试然后它开始工作,但是当我为所有三个编写代码时,只有一个可以工作。
您始终将适配器分配给同一个绑定 属性 mStylePrefSpinner
:
...
mStylePrefSpinner.setAdapter(styleAdapter);
...
mStylePrefSpinner.setAdapter(colorAdapter);
...
mStylePrefSpinner.setAdapter(finishAdapter);
您应该将其设置为每个绑定 属性。假设它们是 mStylePrefSpinner
、mStyleColorSpinner
& mStyleFinishSpinner
:
...
mStylePrefSpinner.setAdapter(styleAdapter);
...
mStyleColorSpinner.setAdapter(colorAdapter);
...
mStyleFinishSpinner.setAdapter(finishAdapter);