【发布时间】:2016-02-19 00:10:16
【问题描述】:
在我的列表视图中,每个项目列表都有一个按钮。当我单击按钮时,按钮颜色从绿色变为红色。但是当我向下滚动时,我看到的第一个项目的颜色按钮也是红色的。为什么我的列表视图中以前的状态视图没有被清除? 这是我的 getView(...) 代码
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) act
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.list_user, null);
}
TextView txtHeader = (TextView) convertView.findViewById(R.id.firstLine);
TextView txtFooter = (TextView) convertView.findViewById(R.id.secondLine);
Button btnAction = (Button) convertView.findViewById(R.id.btn_action);
txtHeader.setText(mDataset.get(position).getUsername());
txtFooter.setText(mDataset.get(position).getId());
btnAction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Button btnAction = (Button)v;
String text = btnAction.getTag().toString();
if(text.equals("start")){
btnAction.setTag("finish");
btnAction.setText("finish");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
btnAction.setBackground(act.getResources().getDrawable(R.drawable.rounded_corner_error));
}
}
}
});
return convertView;
}
【问题讨论】: