Re: Java listener
On 12/25/2011 11:12 PM, Jim Lee wrote:
How do I implement the ConnectionListener interface and how do I pass
it into "httpPost" method to get invoked when "listener event" get
response from the httpPost?
1. Sub-class ConnectionListener to make a concrete class
2. Create an object of that concrete class to pass to httpPost.
As Stefan pointed out, interfaces are not passed as arguments, objects
are, so you need to get an object to pass as a parameter.
public class MyListener implements ConnectionListener {
public void onConnection(int status, InputStream is,
HttpMessage message) {
System.out.println( "onConnection invoked" );
}
public void onConnectionException(Exception e){
System.out.println( "onConnectionException invoked" ) {
}
}
=====================================
public void httpPost(String url, List<Header> headers, HttpEntity
body, ConnectionListener listener) {
MyListener listener = new MyListener();
HttpPostTask task = new HttpPostTask(url, headers, body,
listener);
mExecutor.submit(task);
}
=====================================