Wednesday, August 31, 2011

[android-developers] Re: use listview get web data

public class Tab1Activity<Listview> extends Activity implements
OnClickListener{

private Button get;
private TextView tv;
private DefaultHttpClient client;
private HttpPost request2;
private HttpResponse response;
private ListView listview1;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.tab1main);

tv = (TextView)findViewById(R.id.tv);
client = new DefaultHttpClient();
request2 = new HttpPost();

try {

List<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>(2);
request2.setEntity(new UrlEncodedFormEntity(nameValuePairs));
request2.setURI(new URI("http://172.16.152.152:8081/dking/
not_returnt.php
"));

response = client.execute(request2);

HttpEntity entity = response.getEntity();

byte[] buf = new byte[5000];
BufferedInputStream bin = new
BufferedInputStream(entity.getContent());
bin.read(buf);
bin.close();

String result = new String(buf);

tv.append(result);

} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


this is my source code
data don't put in listview......

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment