0

I have two questions

First, I have a for loop, with every element in this loop i want to set the Name String as a TextView and the Url to a Button, Then to position those TextViews and Buttons vertically under each other Programmatically.

Second, i want those buttons to work for e.g if i click it then start downloading some from it's url.

To be clear this is my for loop

for(int i = 0; i < Array.length; i++) {

    // This contains a String
    String Name = "...";

    // This contains a video url that i want to download onClick
    String Url = "...";

}

What is the best way to do this?

Amr SubZero
  • 1,196
  • 5
  • 19
  • 30

1 Answers1

1

create linearLayout and place your elements int it

do it like

for(int i = 0; i < Array.length; i++) {

    // This contains a String
String Name = "...";

    // This contains a video url that i want to download onClick
String Url = "...";
LinearLayout ll = new LinearLayout(context);
TextView tv = new TextView(context);
Button b = new Button(context);

ll.setOrientation(VERTICAL);
ll.addView(tv);
tv.setText(Name);
ll.addView(b);
b.setOnClickListener(View.OnClickListener() {
                             @Override
                             public void onClick(View v) {
                                downloadVideo(url);
                             }
                         });
addView(ll);
}

to Download url you can use alot of methods like the one mentioned here

Community
  • 1
  • 1
Muhannad Fakhouri
  • 1,468
  • 11
  • 14