更新下面的程序流程顯示了我的預期(「阿爾法」中的自動完成列表):AutoCompleteTextView不arrayadapter項目
打開應用程序 - >點擊按鈕 - >自動完成上自來水場 - >鍵入「人「
但是這一次失敗(如果我輸入‘BR’,‘布拉沃’仍然在名單):
打開應用程序 - 在自動完成場>水龍頭 - >輸入任何東西,然後將其刪除 - >點擊按鈕 - >點擊自動完成字段 - >輸入「al」
爲什麼列表中我在第二個序列中沒有更新?
public class DisplayFragment extends Fragment {
AutoCompleteTextView autoCTVShop;
Button buttonSend;
String[] names= {"Bravo","Charlie","Delta","Foxtrot"};
ArrayAdapter<String> adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_display, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
autoCTVShop = (AutoCompleteTextView) getActivity().findViewById(R.id.autoCompleteTextViewShop);
adapter = new ArrayAdapter<String>(getActivity().getApplicationContext(),
android.R.layout.simple_list_item_1, names);
autoCTVShop.setAdapter(adapter);
buttonSend = (Button) getActivity().findViewById(R.id.buttonSend);
buttonSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//The following two lines don't work as I expected
names[0]="Alfa";
adapter.notifyDataSetChanged();
}
});
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
}
fragment_display.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<AutoCompleteTextView
android:id="@+id/autoCompleteTextViewShop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:imeOptions="actionNext"
android:singleLine="true" />
<Button
android:id="@+id/buttonSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:enabled="true"
android:text="Button" />
</LinearLayout>
感謝。
謝謝,@ N.T。非常明確的解釋。 – Javier