how can I show a loading image when this code running ?
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.google.com");
try
{
HttpResponse response = client.execute(request);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line;
StringBuilder str = new StringBuilder();
while((line = reader.readLine()) != null) {
str.append(line);
}
objwebview.loadData(str.toString(), "text/html", "UTF-8");
}
catch(Exception e)
{
e.printStackTrace();
objwebview.loadData(e.toString(), "text/html", "UTF-8");
}
Change your code as for showing loading bar using AsyncTask
for executing this AsyncTask from UI Thread use
and you can also use
onProgressUpdateandpublishProgressfor showing loading bar usingAsyncTaskand publishing results to Ui thread . for more info seehttp://developer.android.com/reference/android/os/AsyncTask.html