私はAndroidチュートリアルのリストを追加するセクションの余分なクレジットセクションを行っています。私は、ArrayAdapterに含まれている項目でAutoCompleteTextView(ACTV)を設定しようとしましたが、addr項目にしきい値の上限を超える文字が含まれていると、リストに項目が表示されません。ここでは、コードは次のとおりです。AutoCompleteTextViewはListView内の項目を消滅させます
public class MyActivity extends Activity
{
List<Restaurant> model = new ArrayList<Restaurant>();
ArrayAdapter<Restaurant> adapter = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button save = (Button)findViewById(R.id.save);
save.setOnClickListener(onSave);
ListView list = (ListView)findViewById(R.id.restaurants);
adapter = new ArrayAdapter<Restaurant>(this,
android.R.layout.simple_list_item_1,
model);
list.setAdapter(adapter);
AutoCompleteTextView textView = (AutoCompleteTextView)findViewById(R.id.addr);
textView.setAdapter(adapter);
}
private View.OnClickListener onSave= new View.OnClickListener(){
...
};
}
そしてXML ... completionThresholdを変更
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<TableLayout
android:id="@+id/details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:shrinkColumns="1"
android:layout_alignParentBottom="true"
>
<TableRow>
<TextView android:text="Name:"/>
<EditText android:id="@+id/name"/>
</TableRow>
<TableRow>
<TextView android:text="Address:"/>
<AutoCompleteTextView android:id="@+id/addr"
android:completionThreshold="5"
/>
</TableRow>
<TableRow>
<TextView android:text="Type:"/>
<RadioGroup android:id="@+id/types">
<RadioButton android:id="@+id/take_out"
android:text="Take Out"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:checked="true"
/>
<RadioButton android:id="@+id/sit_down"
android:text="Sit Down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton android:id="@+id/delivery"
android:text="Delivery"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</RadioGroup>
</TableRow>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/save"
android:text="Save"/>
</TableLayout>
<ListView android:id="@+id/restaurants"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="@id/details"/>
</RelativeLayout>
は、リスト内の項目が消える前に、私が入力できる文字数を変更します。ヘルプ
消えるアイテムが修正されています。別々のアダプタが必要な理由について詳しく説明できますか?また、リストのデータを使って提案リストをどのように作成しますか?現在、ハードコードされた文字列からは動作しますが、リストのデータでは機能しません。 – Richard
@リチャード:「別々のアダプタがなぜ必要なのか、詳しく説明できますか?」なぜなら、2つのホスティングの 'AdapterViews'、特にあなたの' AutoCompleteTextView'で使われているフィルターの間で異なる必要があるデータを保持しているからです。あなたが提供した限られた情報があれば、私は残りの部分でお手伝いできません。 – CommonsWare
もちろんです。愚かな間違い。助けてくれてありがとう。 – Richard