0

Im creating a app that takes in a string and divides it into words and reprints them while checking if there is a '#' in front of the words. If there is a '#' the color of that word is changed. The problem i am having is the String gets cut if the original String is too long. any help?

public class MainActivity extends Activity {
    String[] parts; 
    LinearLayout.LayoutParams layoutParams ;
    int size;
    LinearLayout L;
    String s ="This is the test String that is divided #Testing ";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        L=(LinearLayout)findViewById(R.id.ll);

        layoutParams= new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,  LinearLayout.LayoutParams.WRAP_CONTENT);

        parts = s.split(" ");
        size = parts.length;

        for(int i=0; i<size;i++)
        {
            TextView valueTV = new TextView(this);
            String d= parts[i] + " ";
            valueTV.setText(d);
            //   valueTV.setLayoutParams(layoutParams);

            if(d.charAt(0)=='#') 
            {
                valueTV.setTextColor(Color.CYAN);
            }
            L.addView(valueTV,layoutParams);
        }

    }

}
Salman Zaidi
  • 9,342
  • 12
  • 44
  • 61
Samantha
  • 199
  • 5
  • 15

1 Answers1

0

It is because you are having linear layout and it takes horizontal orientation.

It will display the text views upto your phone edge and after that your data will not be visible.

You need to check the device display width and manually add another layout if the textView's width exceeds the display width.

Refer this link

It will help you resolve your problem.

Community
  • 1
  • 1
Priya
  • 489
  • 1
  • 10
  • 20