I'm trying to add programmatically a variable quantity of buttons to an Activity.
So I'm starting from a populated hashmap like this:
Map<String, String> map = new HashMap<String, String>();
Then I loop to get data and to make the buttons:
int k = 0;
RelativeLayout layout = (RelativeLayout) findViewById(R.id.layrelative);
for(Entry<String,String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
Button b = new Button(Peli.this);
b.setId(k);
b.setText(key);
b.setOnClickListener(Peli.this);
layout.addView(b);
k++;
}
The problem is that I'm only getting not more than one button, but if I Log the loop the data is OK to generate more than one button, wich by the way, si always the last data from the last iteration.
What am I doing wrong? I've tested also with an Iterator with the same results, so i've think that my mistake is with the addView method or with the creation of every button view.
Thanks in advance.