gpt4 book ai didi

java - 如何在 JSON for 循环中设置 onClick Listener 以检索单击的项目或文本?

转载 作者:太空宇宙 更新时间:2023-11-04 10:19:19 25 4
gpt4 key购买 nike

我正在尝试检索单击的文本并将其复制到剪贴板,但是当我在 for 循环中执行此操作时,尽管仅复制单击的文本,但所有文本都会复制到剪贴板。

               private void jsonParse() {

String url = "https://gist.githubusercontent.com/nasrulhazim/54b659e43b1035215cd0ba1d4577ee80/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json";
request = new JsonObjectRequest(Request.Method.GET, url, null,
new com.android.volley.Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("quotes");

for (int i = 0; i < 60; i++) {
quotes = jsonArray.getJSONObject(i);
String quote = quotes.getString("quote");
String author = quotes.getString("author");
quoteTextView.append("→ " + quote + "\n" + "By - " + author + "\n\n");
String copy = quotes.getString("quote");

}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});

}

提前致谢。

最佳答案

您可以在 textView 上添加 OnClick

然后获取用户点击的文本。

 quoteTextView.getText();

关于java - 如何在 JSON for 循环中设置 onClick Listener 以检索单击的项目或文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51336338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com