public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
int type = getItemViewType(position);
if (convertView == null) {
holder = new ViewHolder();
switch (type) {
case TYPE_ITEM:
System.out.println("getView position " + position);
convertView = mInflater.inflate(R.layout.groupitem, null);
holder.textView = (TextView) convertView
.findViewById(R.id.textitem);
holder.btn = (Button) convertView
.findViewById(R.id.button1);
holder.btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(),
"Clickable button", Toast.LENGTH_LONG)
.show();
// TODO Auto-generated method stub
}
});
break;
case TYPE_SEPARATOR:
convertView = mInflater.inflate(R.layout.groupheader, null);
holder.textView = (TextView) convertView
.findViewById(R.id.textSeparator);
break;
}
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if(position==1){
convertView.setBackgroundResource(R.drawable.celltop);
}
else if (position>1 && position!=1) {
convertView.setBackgroundResource(R.drawable.cellcenter);
}
holder.textView.setText(mData.get(position));
return convertView;
}
开始时它的背景是正确的。但是当我向下滚动列表并再次返回顶部其背景更改时。例如,单元格顶部背景位于顶部,即标题。我只想为项目设置背景