[英]Android pass variable from Java activity to Kotlin adapter
我不知道为什么我对此空白...但是我有一个显示评论的java活动...我需要将正在评论的照片的ID传递给获取所有的适配器注释。 该适配器称为 CommentGrabber:
commentGrabber = new CommentGrabber(this);
...它是这样执行的:
private void requestComment() {
commentGrabber.getComment();
}
当前照片的“id”变量可以随时通过获取其意图来获得,但我已将其保存到名为“photo_id”的字符串中。
final String photo_id = getIntent().getStringExtra("id");
这是适配器端的样子:
fun getComment(String photo_id) {
//this is where the function is handled
}
所以我只需要弄清楚如何从我的评论活动中获取“photo_id”到适配器中的“getComment”。
我会让适配器方法期望如下参数:
fun getComment(photo_id : String) {
// from there then pass the photo_id to the service call
}
然后你会这样称呼它:
adapter.getComment(photo_id);
每当您想按 id 获取评论时。
我希望这是有道理的。 如果您需要进一步说明,请随时询问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.