In WPF we can define an array and bind it to our xml. Elements are then automatically generated based on the contents of this array.:
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
this.DataContext = this;
}
ObservableCollection<int> sampleData = new ObservableCollection<int>();
public ObservableCollection<int> SampleData {
get {
if (sampleData.Count <= 0) {
sampleData.Add(1);
sampleData.Add(2);
sampleData.Add(3);
sampleData.Add(4);
}
return sampleData;
}
}
}
<Window x:Class="Sandbox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ListBox ItemsSource="{Binding Path=SampleData}"/>
</Grid>
</Window>
Is something like this possible in android?