package com.example.listview_2; import android.app.Activity; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnLongClickListener; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; public class MainActivity extends Activity implements TextWatcher { private AutoCompleteTextView autoComplete_city; private String[] city_district = new String[] { "阿巴嘎旗-内蒙古", "阿坝-四川", "阿坝-四川", "阿尔山-内蒙古", "阿合奇-新疆", "阿克-甘肃", "阿克苏-新疆", "阿克苏-新疆", "阿克陶-新疆", "阿拉尔-新疆", "阿拉善盟-内蒙古", "阿拉善右旗-内蒙古", "阿拉善左旗-内蒙古", "阿勒泰-新疆", "阿勒泰-新疆", "阿里-西藏", "阿鲁科尔沁旗-内蒙古", "阿荣旗-内蒙古", "阿图什-新疆", "阿瓦提-新疆", "鞍山-辽宁", "安达-黑龙江", "安多-西藏", "安福-江西", "安国-河北", "安化-湖南", "安吉-浙江", "安康-陕西", "安龙-贵州", "安陆-湖北", "安宁-云南", "安平-河北", "安庆-安徽", "安丘-山东", "安仁-湖南", "安塞-陕西", "安顺-贵州", "安图-吉林", "安溪-福建", "安县-四川", "安乡-湖南", "安新-河北", "安阳-河南", "安阳-河南", "安义-江西", "安远-江西", "安岳-四川", "安泽-山西", "黟县-安徽", }; private Button button1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); autoComplete_city = (AutoCompleteTextView) findViewById(R.id.autoComplete_city); button1 = (Button) findViewById(R.id.button1); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, city_district); autoComplete_city.setAdapter(adapter); Log.i("info", "info"); //String city = autoComplete_city.getText().toString(); //String city=autoComplete_city.getAdapter().ge //Log.i("city", city); Log.i("info2", "info2"); autoComplete_city.addTextChangedListener(this); //button1.setText(city); button1.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { // TODO Auto-generated method stub button1.setVisibility(View.GONE); return true; } }); }////onCreate @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub button1.setText(autoComplete_city.getText()); } }///MainActivity