0

I have some code like this:

l = new LinearLayout(this);
        l.setOrientation(LinearLayout.VERTICAL);
        scrollView.addView(l);
        TextView ch = new TextView(this);
        Button ndda = new Button(this);
        ndda.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        Button nddb = new Button(this);
        Button nddc = new Button(this);
        Button nddd = new Button(this);
        ch.setText("ndch");
        ndda.setText("da");
        nddb.setText("db");
        nddc.setText("dc");
        nddd.setText("dd");
        l.addView(ch);
        l.addView(ndda);
        l.addView(nddb);
        l.addView(nddc);
        l.addView(nddd);

now i want to add lot of linear layout( may be 15) in to scroll view. How can I do that with shortly code? and the Button in each linear layout i want to setOnClickListener on them to do some thing. I try to do this with listview but it's alway refresh when scroll, i can't disable refresh. I'm a newbie so pls show me detail. Thank for all

GoldenICE
  • 1
  • 1
  • 2
    You might want to look into using a ListView instead. – Mike M. Jan 06 '15 at 14:53
  • 3
    You can have only one direct child of a ScrollView. If you want to do that then add it inside a main linear layout. – Rohit5k2 Jan 06 '15 at 14:53
  • Yeah @MikeM. is right. From what I can get from this question I feel its better to use ListView or GridView instead. – Rohit5k2 Jan 06 '15 at 14:55
  • As i said i try it with listview but listview alway refresh when scroll. i use view holder but get a new problem. Did u know how to disable that refresh? i just change the background of button when click on it but when i scroll it background return first. – GoldenICE Jan 06 '15 at 15:09
  • http://stackoverflow.com/questions/27774470/fix-code-custom-listview – GoldenICE Jan 06 '15 at 15:12

1 Answers1

0

Some guys already mentioned it before in the comments... use a ListView or even better ... a RecyclerView.

Here's a good tutorial for the RecylcerView.

Nevertheless a ScrollViewcan have only 1 child (in your case a LinearLayout), which again can contain multiple layouts within.

Kody
  • 1,154
  • 3
  • 14
  • 31