我最近开始使用 Android Studio 3.1.2 和 SDK 19 编写我的第一个 Android 项目。
我的一个片段包含一个带有自定义 RecyclerView.Adapter 的 RecyclerView。在适配器通过其 ViewHolder 获取的 CardView 上,可以有一个按钮。目标是,如果按下按钮,则应调用我的片段的方法,尽管它是 Fragment 的自定义子类的实例:
从请求片段:
public abstract class RequestingFragment extends Fragment implements RequestCallbacks {
public final static void startRequest(final RequestOperation, String param) {
//this is the guy i want to call
}
//these are the RequestCallbacks, they're all getting called in startRequest()
public void onSuccess(JSONObject json, String parsingkey) { }
public void onError() { }
public void onFinished() { }
Run Code Online (Sandbox Code Playgroud)
现在我的RequestingFragment …
目标:带有内置分隔符的字符串应拆分为一个 int 和另一个字符串。如果分隔符序列 '###' 出现多次,则字符串应始终拼接在最后一个 '###' 处。
是否有像 string.lastIndexOf("###") 这样的运算符,就像在 C# 中一样?
这是我的解析器的样子:
func parseTuple(from string: String) -> (String, Int)? {
let parsedString = string.components(separatedBy: "###")
if let tupleString = String(parsedString[0]), let tupleInt = Int(parsedString[1]) {
return (tupleString, tupleInt)
} else {
return nil
}
}
Run Code Online (Sandbox Code Playgroud)