I need help explaing the following example below (c) CommonsWare. I know it makes a subclass of Arraydapter to produce custom listviews.
However I don't understand these rows:
IconicAdapter() {
super(DynamicDemo.this, R.layout.row, items);
}
What does super() do? And what will the arguments be good for? Why do I need pass "items" as an argument but not the other array that is called "rating" ?
Full code:
public class DynamicDemo extends ListActivity {
private String[] items = { "lorem", "ipsum", "dolor", "sit", "amet",
"consectetuer", "adipiscing", "elit", "morbi", "vel", "ligula",
"vitae", "arcu", "aliquet", "mollis", "etiam", "vel", "erat",
"placerat", "ante", "porttitor", "sodales", "pellentesque",
"augue", "purus" };
private String[] rating = { "25%", "65%", "95%", "55%", "15%", "25%r",
"25%", "25%", "25%", "25%", "25%", "25%", "25%", "25%", "25%",
"25%", "25%", "25%", "25%", "25%", "25%", "25%", "25%", "25%",
"25%" };
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
setListAdapter(new IconicAdapter());
}
public void onListItemClick(ListView parent, View v, int position, long id) {
selection.setText(items[position]);
}
class IconicAdapter extends ArrayAdapter<String> {
IconicAdapter() {
super(DynamicDemo.this, R.layout.row, items);
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.row, parent, false);
TextView label = (TextView) row.findViewById(R.id.label);
TextView label2 = (TextView) row.findViewById(R.id.label2);
label.setText(items[position]);
label2.setText(rating[position]);
return (row);
}
}
}