cool endyk, thanks. On Jul 28, 8:26 am, endyk <nit...@gmail.com> wrote: > hello Droid, > > you can use this method to get return string from server > > private InputStream OpenHttpConnection(String urlString) > throws IOException > { > InputStream in = null; > int response = -1; > > URL url = new URL(urlString); > URLConnection conn = url.openConnection(); > > if (!(conn instanceof HttpURLConnection)) > throw new IOException("Not an HTTP connection"); > > try{ > HttpURLConnection httpConn = (HttpURLConnection) conn; > httpConn.setAllowUserInteraction(false); > httpConn.setInstanceFollowRedirects(true); > httpConn.setRequestMethod("GET"); > httpConn.connect(); > > response = httpConn.getResponseCode(); > if (response == HttpURLConnection.HTTP_OK) { > in = > httpConn.getInputStream(); > } > } > catch (Exception ex) > { > throw new IOException("Error connecting"); > } > return in; > } > > private String DownloadText(String URL) > { > int BUFFER_SIZE = 2000; > InputStream in = null; > try { > in = OpenHttpConnection(URL); > } catch (IOException e1) { > // TODO Auto-generated catch block > e1.printStackTrace(); > return ""; > } > > InputStreamReader isr = new InputStreamReader(in); > int charRead; > String str = ""; > char[] inputBuffer = new char[BUFFER_SIZE]; > try { > while ((charRead = isr.read(inputBuffer))>0) > { > //---convert the chars to a String--- > String readString = > String.copyValueOf(inputBuffer, 0, > charRead); > str += readString; > inputBuffer = new char[BUFFER_SIZE]; > } > in.close(); > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > return ""; > } > return str; > } > > try call this function in your main code, where str is return string > from server > > String str = DownloadText("http://kabarku.com/androidwww/endyk- > test.php"); > textView.setText(str); > > extend your self that code, happy coding :) > > On Jul 27, 7:30 pm, Droid <rod...@gmail.com> wrote: > > > > > > > > > I am looking for an example of how to get lines of text from a web > > server query into simple TextViews - NOT WebViews. > > > I have found complex examples with all types of extras that make it > > horrifically difficult to follow. This example is way too hard for > > me:http://www.ibm.com/developerworks/xml/library/x-dataAndroid/ > > > Can some kind person point me at a straightforward example. I think I > > need an Async Task or some type of web fetch thread involved.
-- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en