autocomplete下拉选中事件怎么写? 200
1个回答
2016-07-04
展开全部
具体代码如下WikiSuggestActivityimportorg.apache.http.client.HttpClient;importorg.apache.http.client.ResponseHandler;importorg.apache.http.client.methods.HttpGet;importorg.apache.http.impl.client.BasicResponseHandler;importorg.apache.http.impl.client.DefaultHttpClient;importorg.json.JSONArray;importandroid.app.Activity;importandroid.os.AsyncTask;importandroid.os.Bundle;importandroid.text.Editable;importandroid.text.TextWatcher;importandroid.util.Log;importandroid.widget.ArrayAdapter;importandroid.widget.AutoCompleteTextView;/***@Title:WikiSuggestActivity.java*@Packagecom.yang.testautocompletetextview*@Description:参考plete-in-android-not-working-with-dynamic-data*@authorYang*@date2012-8-12下午2:59:54*@versionV1.0*/publicclassWikiSuggestActivityextendsActivity{publicStringdata;publicListsuggest;publicAutoCompleteTextViewautoComplete;publicArrayAdapteraAdapter;@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);suggest=newArrayList();autoComplete=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);autoComplete.addTextChangedListener(newTextWatcher(){publicvoidafterTextChanged(Editableeditable){}publicvoidbeforeTextChanged(CharSequences,intstart,intcount,intafter){}publicvoidonTextChanged(CharSequences,intstart,intbefore,intcount){StringnewText=s.toString();newgetJson().execute(newText);}});}classgetJsonextendsAsyncTask{@OverrideprotectedvoidonPostExecute(Stringresult){super.onPostExecute(result);aAdapter=newArrayAdapter(getApplicationContext(),R.layout.item,suggest);autoComplete.setAdapter(aAdapter);aAdapter.notifyDataSetChanged();}@OverrideprotectedStringdoInBackground(Stringkey){StringnewText=key[0];newText=newText.trim();newText=newText.replace("","+");try{HttpClienthClient=newDefaultHttpClient();HttpGethGet=newHttpGet("api.php?action=opensearch&search="+newText+"&limit=8&namespace=0&format=json");ResponseHandlerrHandler=newBasicResponseHandler();data=hClient.execute(hGet,rHandler);suggest=newArrayList();JSONArrayjArray=newJSONArray(data);for(inti=0;iitem.xml
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询