У меня есть функция, которая заполняет мою базу данных SQLite записями http-запроса:
try {
stringEntity = new StringEntity(SQL);
httpPost.setEntity(stringEntity);
httpResponse = httpClient.execute(httpPost);
httpEntity = httpResponse.getEntity();
bos = new ByteArrayOutputStream();
httpEntity.writeTo(bos);
data = bos.toString();
reader = new BufferedReader(
new StringReader(data));
try {
//SAVE DATA IN MY DB || WORKS
} catch(IOException e) {
e.printStackTrace();
}
} catch (IOException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
То, что я пытаюсь сделать, это установить текст textview для моей деятельности перед началом процедуры (перед первым "try {.." в моем коде, который я постет).
но текст не изменится, потому что моя деятельность слишком занята, чтобы получить данные (я думаю. У меня нет другого объяснения ..)
есть предложения?
спасибо,
* prexx 1008 *
UPDATE
'' Получить данные из AsyncTask ''
txtAction.setText("Loading...");
AsyncTask<String, String, String> test = new cAsyncTask();
try {
data = test.execute(URL).get();
reader = new BufferedReader(
new StringReader(data));
while ((line = reader.readLine()) != null) {
//SAVE DATA IN DB || WORKS
}
}
} catch(IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Моя асинхронная задача:
class cAsyncTask extends AsyncTask<String, String, String> {
protected String doInBackground(String... urls) {
int count = urls.length;
String data = "";
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost;
StringEntity stringEntity;
HttpResponse httpResponse;
HttpEntity httpEntity;
ByteArrayOutputStream bos;
String line;
BufferedReader reader;
for (int i = 0; i < count; i++) {
httpPost = new HttpPost(urls[i].toString());
try {
stringEntity = new StringEntity(SQL);
httpPost.setEntity(stringEntity);
httpResponse = httpClient.execute(httpPost);
httpEntity = httpResponse.getEntity();
bos = new ByteArrayOutputStream();
httpEntity.writeTo(bos);
data = bos.toString();
} catch (IOException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
}
return data;
}
protected void onProgressUpdate(String... progress) {
}
protected void onPostExecute(String result) {
String test = result;
}