[英]How do I set onClick Listener in JSON for loop in order to retrieve the clicked item or text?
I am trying to retrieve the clicked text and to copy it to clipboard but when i do so in my for loop, despite on copying only the clicked text all the text gets copied to clipboard. 我正在尝试检索单击的文本并将其复制到剪贴板,但是当我在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();
}
});
}
Thanks in advance. 提前致谢。
You can add OnClick on your textView 您可以在textView上添加OnClick
and then get the Text on which the user clicks. 然后获取用户单击的文本。
quoteTextView.getText();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.