这是我的代码,但是当我运行它时,输出与我不想要的所有列表视图行相同。
我想要所有行的独立输出.....
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
Log.v("ConvertView", String.valueOf(position));
if (convertView == null) {
ViewHolder holder1 = new ViewHolder();
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.state_info, null);
// this.setPosition(position);
holder = new ViewHolder();
holder.position = getPosition();
holder.state = stateList.get(position);
holder.code = (TextView) convertView.findViewById(R.id.code);
holder.name = (CheckBox) convertView.findViewById(R.id.checkBox1);
holder.num = (TextView) convertView.findViewById(R.id.up_down_button_value);
holder.up = (ImageButton) convertView.findViewById(R.id.up_down_button_up);
holder.down = (ImageButton) convertView.findViewById(R.id.up_down_button_down);
holder.value = (TextView) convertView.findViewById(R.id.qnt1);
convertView.setTag(holder);
holder.name.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
States state = (States) cb.getTag();
//Toast.makeText(getApplicationContext(),"Clicked on Checkbox: " + cb.getText() +" is " + cb.isChecked(),Toast.LENGTH_LONG).show();
state.setSelected(cb.isChecked());
}
});
holder.up.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
_value++;
holder.num.setText(_value);
}
});
holder.down.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
_value--;
holder.num.setText(_value);
}
});
} else {
holder = (ViewHolder) convertView.getTag();
}
States state = stateList.get(position);
holder.code.setText(" (" + state.getCode() + ")");
holder.name.setText(state.getName());
holder.name.setChecked(state.isSelected());
//holder.num.setText(state.getNum());
holder.name.setTag(state);
// checkIncButtonClick();
// checkDecButtonClick();
return convertView;
}
输出 :
item item quantity : 2 b1 t1 b2
b1
b2
是两个按钮,是t1
1 行列表视图的文本视图,2 是文本视图 1 的值
就像我点击按钮时值增加或减少,最后分配到 2