Here goes a small code for looping in android using java.
Layout to which we add views
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:id="@+id/content">
</LinearLayout>
Lets create views in for loop and add to above layout
LinearLayout content=(LinearLayout)findViewById(R.id.content);
int[5] x={1,2,3,4,5};
for(int i:x)
{
Button butn=new Button(getApplicationContext());
butn.setTag(i); // used for identifying individually each button
content.addView(butn);
}
Layout to which we add views
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:id="@+id/content">
</LinearLayout>
Lets create views in for loop and add to above layout
LinearLayout content=(LinearLayout)findViewById(R.id.content);
int[5] x={1,2,3,4,5};
for(int i:x)
{
Button butn=new Button(getApplicationContext());
butn.setTag(i); // used for identifying individually each button
content.addView(butn);
}
0 comments:
Post a Comment