[英]android autocompletetextview inside asynctask not showing
我已經成功地將AutoCompleteTextView鏈接到MySQL中找到的數據,此外,我為此使用了AsyncTask。 我想知道的是如何在TextView中顯示下拉列表。 我知道我正確地獲取了數據,因為它顯示在System.err.println()方法中。 這是我的代碼。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_httpentity);
AutoCompleteTextView locationupdate;
// This is an issue I do not know how to hook
// My autocompleteTextview here
AutoLocation mytask= new AutoLocation();
mytask.execute();
}
private class AutoLocation extends AsyncTask<String,String,String> {
String line,tryy="";
AutoCompleteTextView locationupdate;
@Override
protected void onPreExecute() {
super.onPreExecute();
locationupdate=(AutoCompleteTextView)findViewById(R.id.locationupdate);
}
@Override
protected String doInBackground(String...params) {
try {
InputStream in = new BufferedInputStream(conn.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
// Other code here that I omitted because it is correct
while ((line = reader.readLine()) != null) {
tryy+= result.append(line);
}
// tryy contains the MySQL data and it works successfully
// because I can see output in System.err.println()
System.err.println(tryy);
}
catch (IOException e) {
e.printStackTrace();
}
return tryy;
}
protected void onPostExecute(List<String> result)
{
// How can I pass tryy into my adapter here?
ArrayAdapter<String> adapter= new ArrayAdapter<>
(Httpentity.this,android.R.layout.simple_dropdown_item_1line,result);
locationupdate.setAdapter(adapter);
}
//Async Ends
}
從上面可以看到, tryy字符串包含來自MySQL的數據。 我只是不知道如何將其傳遞給onPostExecute中的適配器。 另一個問題只是我現在如何將其傳遞給onCreate方法? 例如,如果這是一個click方法,那么您可以使用setOnclick然后在單擊時執行Async,但是AutocompleteTextview呢? 這是關於TextWatcher的討論,但我似乎無法實現任何建議都很好。. 使用MySQL數據的AutoCompleteTextView
ArrayAdapter<String> adapter= new ArrayAdapter<>(Httpentity.this,android.R.layout.simple_dropdown_item_1line,result);
locationupdate.setAdapter(adapter);
之后放置locationupdate.showDropDown();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.