I have a list view that displays two different kinds of data one is a separator. Each data type is stored in one array list. Thus there are two lists. The content of each list is separated from the other one by a special row (separator). The first row is a separator row as well. In getView
i have to distinguish between normal data rows and separator rows.
// returns true if a separator row must be displayed at pos.
private boolean isSeperator(int pos) {
return pos == 0 || pos == data.size() + 1;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(isSeperator(position)) {
convertView = infalInflater.inflate(R.layout.list_view_seperator, parent, false);
TextView seperator = (TextView) convertView.findViewById(R.id.tv_list_view_seperator);
seperator.setText("Seperator");
}
else {
convertView = infalInflater.inflate(R.layout.my_layout, parent, false);
TextView txtview = (TextView) convertView.findViewById(R.id.foo);
ImageView icon = (ImageView) convertView.findViewById(R.id.bar);
MyData myData = (MyData) getItem(position);
txtview.setText(myData.getName());
icon.setImageBitmap(myData.getIcon());
}
return convertView;
}
First I check whether a separator has to be displayed on the current position. This works fine.
I tried to implement the view holder pattern, but I constantly fail. Can somebody could please show me how to use this pattern in such a case where different types of rows including separators must be taken into consideration?