0

I am developing an calculator app. That app take input using edit text and shows the value in a textview using setText. Some times the input get bigger and it becomes hard to fit the output in a single line. That's why I need to spilt the output into multiple line. I've used some line separator solutions from SO but nothing properly works for me.

Please give me a solution to show a way to show the output text into multiple line. Please don't flag as similar .
Note: All my input and output are number and they have no space or punctuation mark in them.

Thanks in Advance.

  • Here's an idea; Use EditText and set it to multiline with scroll for output instead of TextView. This will also let users copy previous numbers and reuse them elsewhere or in the same app again. – MD Naseem Ashraf Mar 13 '19 at 04:00
  • That could be an idea. Thanks but I need the mentioned one. – K M Rejowan Ahmmed Mar 13 '19 at 04:03
  • https://stackoverflow.com/questions/1748977/making-textview-scrollable-on-android – MD Naseem Ashraf Mar 13 '19 at 04:04
  • That thread is about vertically scroll. I know that. I want a separator after a certain word count. – K M Rejowan Ahmmed Mar 13 '19 at 04:07
  • 1
    Can you provide a screenshot of what is and what you want to achieve? If you can make your question clear it will help you get quicker responses. – MD Naseem Ashraf Mar 13 '19 at 04:12
  • My output could be like - 1010101110001101011010011100111000111100001110000 which is too big to fit in one line. I want to spilt it into 1010101110001101011010011 100111000111100001110000 – K M Rejowan Ahmmed Mar 13 '19 at 04:22
  • Put a screenshot in your question and rewrite your question to make it clear for others to help you quickly. What have you attempted till now, what does your current output look like and its XML Layout? Attach those to the question. I'd again suggest you go for an EditText with multiline and scrollbars. – MD Naseem Ashraf Mar 13 '19 at 04:26
  • why not just insert a "\n" at every n interval for your long string? https://www.geeksforgeeks.org/insert-a-string-into-another-string-in-java/ – Angel Koh Mar 13 '19 at 04:31
  • Have you tried using "Auto sizing textviews"? – Taseer Mar 13 '19 at 04:38
  • @AngelKoh that string is an output of users input. It can't be set with \n . – K M Rejowan Ahmmed Mar 13 '19 at 04:53
  • Autosizing text view only works in API level 26 and up. and that will only change the text size, not usable for multiple lline. – K M Rejowan Ahmmed Mar 13 '19 at 04:54
  • @KMRejowanAhmmed can you post your xml file for this activity – Jeeva Mar 13 '19 at 06:28

1 Answers1

0

Im not allowed to comment yet. So have u heard of "Spanned"? Im Using kotlin and Assuming max items in one line is 20 . Try This:

    String yourString  = "1010101110001101011010011100111000111100001110000";
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(yourString);

    for(int i = 0; i<yourString.length();i++){
        if(i%20 == 0){
            stringBuilder.insert(i,"<br/>");
        }
    }
    Spanned spannedString = Html.fromHtml(stringBuilder.toString());

    yourtextView.setText(spannedString);

feel free to give feedback.

Rinat Diushenov
  • 1,316
  • 4
  • 10