0

I have managed to extract the first letters on a sentence and store that into a variable.

String[] result = matches.toString().split("\\s+");
        // The string we'll create

        String abbrev = "";



           // Loop over the results from the string splitting
           for (int i = 0; i < result.length; i++){

               // Grab the first character of this entry
               char c = result[i].charAt(0);

               // If its a number, add the whole number
               if (c >= '0' && c <= '9'){
                   abbrev += result[i];
               }

               // If its not a number, just append the character
               else{
                   abbrev += c;
               }
           }

I then store the values into a Final String Array;

           List<String> list = Arrays.asList(abbrev);
          final String[] cs12 = list.toArray(new String[list.size()]);

I then set the values into a alert dialog as follows:

                 builder2.setItems(cs12[0].toString().split(","), new DialogInterface.OnClickListener(){

My next task is when the user selects one of the items for it to go into the text view. However it doesn't let me do this.

   public void onClick(DialogInterface dialog, int item) {
                 TextView speechText = (TextView)findViewById(R.id.autoCompleteTextView1);            
                speechText.setText(Arrays.toString(cs12));

                //   TextView speechText = (TextView)findViewById(R.id.autoCompleteTextView1);            
                  // speechText.setText(matches.get(item).toString());  

However for my other parts matches.get works fine but I cant seem to get cs12.get.

Any Ideas?

Thanks

1 Answer 1

2

Use cs12[0].toString().split(",")[item] to show selected item in TextView:

String[] strArr= cs12[0].toString().split(",");
speechText.setText(strArr[item]);
Sign up to request clarification or add additional context in comments.

2 Comments

@BasicCoder: one more suggestion instead of calling split again add String[] strArr= cs12[0].toString().split(","); line before builder2.setItems line and pass strArr as first parameter to setItems and use same Array instead onClick to get selected item
I appreciate it (I had to wait 5 minutes)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.