1

Alright, I'm trying to create textviews dynamically with strings i have in an array. Everything works right now besides when i create the textviews instead of them going down they each stay on the same line and run off the screen. I want each textview i create under the next. Code Below works just need it to create under the next instead all on one line.

public void GenList(){
    DataBase entry = new DataBase(this);
    entry.open();
    String data = entry.getData();
    int datanumber = entry.FindShit();
    if(datanumber == 0 || datanumber == 1){
        setContentView(R.layout.nowordlist);
    }else{

    int length = entry.results.length;
    View linearLayout =  findViewById(R.id.sayLinear);
    for(int i=0;i<length;i++)
    {
        TextView value = new TextView(this);
        value.setText(entry.results[i]);
        value.setId(i);
        value.setTextSize(50);
        value.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        ((LinearLayout) linearLayout).addView(value);

    }




    }
}

1 Answer 1

2

You'll need to change the orientation of the LinearLayout (R.id.sayLinear) you're adding the TextViews to. By default the orientation is set to 'horizontal', which will make the TextViews appear next to each other on a single line. Try changing it to 'vertical':

<LinearLayout
    <!-- other attributes -->
    android:orientation="vertical" />
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks alot, been stuck on this for a while!

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.