I have a list that should have each item the same layout except for the first and last item which should have separate layouts. The first item shows its unique layout correctly, but the last one changes when I scroll it in and out of view between the correct one and the layout of the first item. Here is my adapter:
public class ListAdapterApp extends ArrayAdapter<App> {
Context context;
int layoutResourceId;
List<App> appList;
public ListAdapterApp(Context context, int layoutResourceId, List<App> appList) {
super(context, layoutResourceId, appList);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.appList = appList;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
AppHolder holder = null;
if(row == null)
{
holder = new AppHolder();
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
if(position == 0){
holder.rowLayoutID = R.layout.list_column_appheaderitem;
} else if(position == appList.size() - 1){
holder.rowLayoutID = R.layout.list_column_appfooteritem;
} else {
holder.rowLayoutID = layoutResourceId;
}
row = inflater.inflate(holder.rowLayoutID, parent, false);//holder.packBackground = (LinearLayout)row.findViewById(R.id.packBackground);
row.setTag(holder);
}
else
{
holder = (AppHolder)row.getTag();
}
App app = appList.get(position);
return row;
}
static class AppHolder
{
public int rowLayoutID;
}
}