简体   繁体   English

如何在JSON for循环中设置onClick侦听器,以检索单击的项目或文本?

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

相关问题 如何从从 onclick 侦听器单击的项目中检索数据 - How to retrieve data from an item that was clicked from an onclick listener 如何将 onClick 监听器设置为 recyclerView? - How do I set onClick listener to recyclerView? 如何将Onclick侦听器设置为动态微调器项目 - How to set Onclick listener to dynamic spinner item 使用导航组件单击 RecyclerView 项目时如何从 RecyclerView OnClick 侦听器更改片段 - How to change fragment from the Recycler View OnClick Listener when RecyclerView item is clicked using Navigation Components 如何将onclick监听器设置为画布? - How to set an onclick listener to a canvas? 如何让我的动作侦听器与我的计算方法进行通信以将文本输出到我的 GUI? - How do I get my action listener to communicate with my calculation methods in order to output text to my GUI? 如何将单击的 ListView 项目的文本发送到我的新活动? - How do I send the text of the ListView item that was clicked to my new activity? 如何设置“项目点击侦听器”上的视图寻呼机? 设置点击监听器不起作用 - How can I set view pager's on Item Click Listener? Set On Click Listener is not working 如何将图像导入黑莓并设置onClick侦听器? - how to get images into blackberry and set an onClick listener? 如何在充气器代码上设置 onclick 侦听器 - How to set onclick listener on inflater code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM