簡體   English   中英

Android 將變量從 Java 活動傳遞到 Kotlin 適配器

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM