简体   繁体   English

如何从字符串中获取所有值?

[英]How to get all values from a String?

I am trying to use Firebase smart replies ML kit to generate responses for text.我正在尝试使用 Firebase 智能回复 ML 套件来生成文本响应。 And i would like update my textview with all three responses.我想用所有三个响应更新我的文本视图。 I already set up my UI and generated the responses how do i retrieve all three responses to populate my textview?我已经设置了我的 UI 并生成了响应我如何检索所有三个响应来填充我的文本视图? I only manage to get one.我只设法得到一个。

public void respondToText(){
        FirebaseSmartReply smartReply = FirebaseNaturalLanguage.getInstance().getSmartReply();
        smartReply.suggestReplies(conversation)
                .addOnSuccessListener(new OnSuccessListener<SmartReplySuggestionResult>() {
                    @Override
                    public void onSuccess(SmartReplySuggestionResult result) {
                        if (result.getStatus() == SmartReplySuggestionResult.STATUS_NOT_SUPPORTED_LANGUAGE) {
                            // The conversation's language isn't supported, so the
                            // the result doesn't contain any suggestions.
                        } else if (result.getStatus() == SmartReplySuggestionResult.STATUS_SUCCESS) {
                            // Task completed successfully
                            for (SmartReplySuggestion suggestion : result.getSuggestions()) {

                                String replyText = suggestion.getText();

                                respongeOne.setText(replyText);
                                responeTwo.setText(responseArray.indexOf(0));
                                responseThree.setText(responseArray.indexOf(2));

                            }
                        }
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        // Task failed with an exception
                        // ...
                    }
                });
    }

result.getSuggestions() returns a list of suggested responses, so you can access those suggestions by index: result.getSuggestions()返回建议响应列表,因此您可以按索引访问这些建议:

responseOne.setText(result.getSuggestions().get(0).getText());
responseTwo.setText(result.getSuggestions().get(1).getText());    
responseThree.setText(result.getSuggestions().get(2).getText());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase 远程配置:如何在 Map 中获取所有配置<string, string></string,> - Firebase Remote Config: How to get all config in Map<String, String> 如何从 firebase 中的集合中的所有文档中获取特定数据? - How to get specific data from all documents from a collection in firebase? 如何从 Firestore 的集合中获取所有文档 - How to get all documents from a collection from Firestore 如何通过在 bigquery sql 中进行分组字符串比较来返回同一列中字符串值的差异? - How to return difference in string values from the same column by doing a grouped string comparison in bigquery sql? 从 python 中的字符串或字典中排除值 - exclude values from a string or dictionar in python 从 Firestore 子集合 flutter 获取所有数据 - get all data from a firestore subcollection flutter 从 Firestore 集合中获取包含所有文档的列表 - Get a list with all documents from a Firestore collection 在 NodeJS 中获取来自 AWS SQS 的所有消息 - Get all messages from AWS SQS in NodeJS 如何从 BigQuery 上 SQL 中的 JSON 字符串中提取嵌套值? - How do I extract nested values from a JSON string in SQL on BigQuery? 试图从 Firestore 获取所有收集数据 - Trying to get all the collection data from Firestore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM