How to create Scrollview programmatically?

后端 未结 5 2234
既然无缘
既然无缘 2021-02-07 20:24

I have one table \"TABLE_SUBJECT\" which contain a number of subjects. I need to create
one horizontal scroll view with Subject.

How do I create a ScrollView with da

5条回答
  •  余生分开走
    2021-02-07 20:57

    this may help you.

        HorizontalScrollView hsrll = (HorizontalScrollView)findViewById(R.id.hrsll);
    
        b = new Button(this);
    
        for (int i = 0; i < 5; i++) {
    
            b.setWidth(LayoutParams.WRAP_CONTENT);
            b.setHeight(LayoutParams.WRAP_CONTENT);
    
            b.setText("b"+i);
            b.setId(100+i);
    
            hsrll.addView(b);
        }
    

    instead of for loop just modify the code as your need(no of records in db). but this the code for creating buttons in dynamically.

提交回复
热议问题