我有带有自定义基本适配器的列表视图。当我填充列表时,我必须检查我正在填充列表视图的对象中的布尔值,以及更改该行的背景颜色是否属实。
public View getView(int position, View convertView, ViewGroup parent) {
LoginsList entry = listOfLoginsLists.get(position);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.lists_row, null);
}
TextView ListName = (TextView) convertView.findViewById(R.id.tvListName);
ListName.setText(entry.getListName());
TextView ListDescription = (TextView) convertView.findViewById(R.id.tvListDescription);
ListDescription.setText(entry.getListDescription());
Button Send = (Button) convertView.findViewById(R.id.bSend);
Send.setOnClickListener(this);
Send.setTag(entry);
RelativeLayout RelLayout = (RelativeLayout) convertView.findViewById(R.id.layoutListsRow);
RelLayout.setFocusableInTouchMode(false);
RelLayout.setFocusable(false);
RelLayout.setOnClickListener(this);
RelLayout.setTag(entry);
if (entry.isSent()) {
RelLayout.setBackgroundColor(Color.parseColor("#4400FF00"));
}
return convertView;
}
但是这段代码不能正常工作。当我滚动列表视图时,行颜色会变得混乱。