用于实现EventListener的普通类

时间:2014-04-05 18:18:42

标签: android events interface

我有这堂课:

public class post2social {

public interface socialResult extends EventListener {
    public void responseResult(String val);
}

public socialResult listener;

private String message, name, caption, descr, URL, picture;
private Context c;
private SocialAuthAdapter adapter;

public post2social(Context c, String message, String name, String caption, String descr, String URL, String picture) {
    this.c = c;

    this.message = message;
    this.name = name;
    this.caption = caption;
    this.descr = descr;
    this.URL = URL;
    this.picture = picture;

    adapter = new SocialAuthAdapter(new ResponseListener());

    try {
        adapter.addConfig(Provider.FACEBOOK, c.getString(R.string.fb1), c.getString(R.string.fb2), null);
        adapter.addConfig(Provider.TWITTER, c.getString(R.string.tw1), c.getString(R.string.tw2), null);
    }
    catch (Exception ex){}
}

private final class MessageListener implements SocialAuthListener<Integer> {
    @Override
    public void onExecute(String provider, Integer t) {
        Integer status = t;
        if (status.intValue() == 200 || status.intValue() == 201 || status.intValue() == 204)
            listener.responseResult("Message posted on " + provider);
}

}

listener.responseResult 举起活动,很好!

现在,在活动中使用此类时, setListener 方法不是变量!

  

post2social s = new post2social(Test.this,“”,“”,“”,“”,“”,);

测试将EventListener实现为类:

  

public class post2social实现EventListener {

再次没有 setListener 方法!任何线索?

1 个答案:

答案 0 :(得分:0)

我想您忘记更改代码的这一行:

adapter = new SocialAuthAdapter(new ResponseListener());

到此:

adapter = new SocialAuthAdapter(this);

当你的post2social类实现EventListener时,你应该把它作为Listener传递给SocailAuthAdapter。