AutoCompleteTextView가있는 앱이 있습니다. 모든 텍스트 변경 이벤트에서 앱은 웹으로 이동하여 인터넷에서 일부 콘텐츠를 검색하고 TextView에 대한 드롭 다운을 채 웁니다. 웹 콘텐트 읽기를 위해 AsyncTask를 사용했다. 그러나 콘텐츠가 수신되고 채워지기 전에 새 텍스트를 입력하면 이전 콘텐츠를 가져올 때까지 앱이 중단됩니다. 문제를 해결할 수있는 방법이 있습니까? 다음과 같이Android : AsyncTask가 예상대로 작동하지 않습니다.
내 AsyncTask를이
private class GetSuggestions extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
System.out.println("Suggestions Called()");
doSearch(params[0]); // reads the web and populates the suggestions ArrayList
return null;
}
@Override
protected void onPostExecute(String result) {
System.out.println("Adapter Called() " + suggestions.size());
suggestionAdapter = new ArrayAdapter<String>(
getApplicationContext(), R.layout.list, suggestions);
searchText.setAdapter(suggestionAdapter);
}
}
들으이다! Rahul.
귀하의 경우에는 귀하가 성취하고자하는 바에 따라 다릅니다. 드롭 다운에있는 것이 무엇이든간에 'TextView'가 무엇이든, 그리고 항상 그 TextView'와 관련이 있다면, 프로세스를 멈추고 새로운 것으로 다시 시작합니다. 그렇지 않다면, 대기리스트를 만들 수 있고,'onPostExecute'가 그리스트를 검사하여 다음에 무엇이 있는지 확인할 수 있습니다. – Andy