改造方法:
@FormUrlEncoded
@POST("api/index.php?m=topic&action=send")
Observable<ApiResponse> sendPost(@Field("id_topic") long id,
@Field("subject") String subject,
@Field("message") String text);
方法调用:
public void sendPost(String subj, String text) {
Subscription subscription = model.sendPost(args.getLong("topic_id"), subj,
text)
.subscribe(new Observer<ApiResponse>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
try {
Log.e("Post wrong", "Error while posted message: " + e.getMessage());
activityCallback.makeToast("Message not published, an error occurred");
} catch (NullPointerException e1) {
Log.e("Error:", "getMessaage() or activityCallback is null");
}
}
@Override
public void onNext(ApiResponse apiResponse) {
try{
activityCallback.makeToast("Message successfully published");
} catch (NullPointerException e) {
Log.e("Error:", "activityCallback is null");
}
reload();
}
});
addSubscription(subscription);
}
@OnClick(R.id.sendButton)
public void send() {
if (sendText.getText() == null
|| sendText.getText().toString().trim().isEmpty()){
makeToast("ÐведиÑе ÑекÑÑ Ð¿ÑбликаÑии");
return;
}
presenter.sendPost("Re: ТеÑÑÐ¾Ð²Ð°Ñ Ñема", sendText.getText().toString());
}
onClick只调用一次。在查看的日志中,请求以相同的方式发送一次。有什么问题?
求求你,救命