2

AutoCompleteTextView の結果リストの最後に「ここをクリックして会場が見つかりません」を追加しようとしています。ユーザーが会場を手動で追加できるように、見つかった結果を表示するにはこれが必要です

ありがとう、

アンディ

public class AddVenueActivity extends Activity implements TextWatcher{
    AutoCompleteTextView venue_auto_complete;
    ArrayList<String> venues = new ArrayList<String>();
    ArrayAdapter<String> adapter = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_addvenue);

        try
        {
            venue_auto_complete = (AutoCompleteTextView) findViewById(R.id.add_venue_autocomplete);
            adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, venues);
            venue_auto_complete.setThreshold(2);
            adapter.setNotifyOnChange(true);
            venue_auto_complete.addTextChangedListener(this);
            venue_auto_complete.setAdapter(adapter);
            venue_auto_complete.setCompletionHint("POWPOWPOW");

            venue_auto_complete.setOnClickListener(new OnClickListener(){
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    venue_auto_complete.setDropDownHeight(LayoutParams.WRAP_CONTENT);
                }
            });

            venue_auto_complete.setOnItemClickListener(new OnItemClickListener(){
                @Override
                public void onItemClick(AdapterView<?> listView, View arg1, int position, long arg3) {
                    try
                    {
                        String venue = (String)listView.getItemAtPosition(position);
                        String[] venue_string_array = venue.split(System.getProperty("line.separator"));
                        venue = venue_string_array[0];
                        venue_auto_complete.setText(venue);
                        venue_auto_complete.dismissDropDown();
                        venue_auto_complete.setDropDownHeight(0);
                    }
                    catch(Exception e)
                    {
                        Log.v("EROORS", e.toString());
                    }
                }
            });
        }
        catch(Exception e)
        {
            e.printStackTrace();
            Log.v("ERROR", e.toString());
        }
    }

    @Override
    public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        if(arg0.length() > 0) 
        {
            search(arg0.toString());
        }

    }

    public void search(String query)
    {
        try
        {
            RequestParams params = new RequestParams();
            params.put("q", query);
            Api.get("/search", params, new JsonHttpResponseHandler() 
            {
                @Override
                public void onSuccess(JSONObject json_response) 
                {
                    try
                    {
                        adapter.clear();

                        JSONArray venue_searchs = json_response.getJSONArray("response");

                        for(int i = 0; i < venue_searchs.length(); i++)
                        {
                            JSONObject venue_search_result = venue_searchs.getJSONObject(i);
                            if(venue_search_result.getString("address") != "null")
                            {
                                adapter.add(venue_search_result.getString("name") + "\n" + venue_search_result.getString("address"));
                            }
                            else
                            {
                                adapter.add(venue_search_result.getString("name"));
                            }
                        }


//                      adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, venues);
                        venue_auto_complete.setAdapter(adapter);
                        adapter.notifyDataSetChanged();
                    }
                    catch(Exception e)
                    {
                        Log.v("ERROR", e.toString());
                    }
                }
            });
        }
        catch(Exception e)
        {
            Log.v("error", e.toString());
        }
    }

}
4

1 に答える 1

1

AdapterをHeaderViewListAdapterでラップし、AutoCompleteTextViewに使用してみてください

このコンストラクターを使用する

headeradapter= new HeaderViewListAdapter(ArrayList<ListView.FixedViewInfo> headerViewInfos, ArrayList<ListView.FixedViewInfo> footerViewInfos, adapter);

venue_auto_complete.setAdapter(headeradapter);
于 2013-03-07T17:49:58.450 に答える