我正在尝试将“无法找到地点单击此处”附加到 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());
}
}
}