im new to android programming and i ran into a problem. here is the code snippet
nums = (GridView) findViewById(R.id.nums);
for(int i=0; i < 10; i++) {
Button b = new Button(this);
b.setText(i+"");
b.setTextSize(15);
b.setTextColor(Color.CYAN);
b.setOnClickListener(numsClickHandler);
nums.addView(b, 20, 20);
}
the problem occurs when it reaches nums.addView(b, 20, 20);
caused by: java.lang.unsupportedoperationexception: addView(View, int, layoutparams) is
not supported in adapterview
The Error message is clear,
GridViewis an AdapterView which does not allow directly adding view to it, rather, it works like ListView that you need to supply an adapter to it, and in your adapter, provide the Views. The GridView tutorial may help.