我有一个 ArrayAdapter:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)LayoutInflater.from(context);
v = vi.inflate(R.layout.consumerlist_row, null);
}
SharedClass.GenericItem item = SharedClass.consumerList.get(position);
if (item != null) {
final GenericItem fitem = item;
v.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int id = ID = ((ExtEditText)v.findViewById(R.id.dayreadout_entry)).getIdentifyingNumber();
if(prevID!=ID){
if(!((ExtEditText)v.findViewById(R.id.dayreadout_entry)).isSelected()
&&!((ExtEditText)v.findViewById(R.id.nightreadout_entry)).isSelected()){
if(fitem.GetIdAddress()==ID){
//Set unique identificator of
((ExtEditText)v.findViewById(R.id.dayreadout_entry)).setChosen(true);
TransitionDrawable drawable = (TransitionDrawable) v.getBackground();
drawable.startTransition(animSpeed);
}
if(prevID!=-1){
CloseEditMode();
LeaveRow(prevRow, prevID);
}
prevRow = v;
prevID=ID;
}
}
}
});
SetColorToRow( v, item);
return v;
}
离开行:
private void LeaveRow(View row, int id){
int ids = ((ExtEditText)row.findViewById(R.id.dayreadout_entry)).getIdentifyingNumber();
if(id==ids){
SharedClass.GenericItem item = GetItemByID(id);
((ExtEditText)row.findViewById(R.id.dayreadout_entry)).setChosen(false);
TransitionDrawable tDrawable = (TransitionDrawable)row.getBackground();
tDrawable.reverseTransition(animSpeed);
}
}
SetColorToRow:
private void SetColorToRow(View v, GenericItem item){
boolean ids = ((ExtEditText)v.findViewById(R.id.dayreadout_entry)).isChosen();
String day = String.valueOf(item.GetDay());
String night = String.valueOf(item.GetNight());
String skipped = String.valueOf(item.GetSkipped());
if(day.equals("-9999999")&&night.equals("-9999999")&&!skipped.equals("0")){
if(ids){
TransitionDrawable td = (TransitionDrawable) v.getBackground();
td.startTransition(animSpeed);
}
else
v.setBackgroundResource(R.drawable.listviewitem_yellow_blue);
}
else if(day.equals("-9999999")&&night.equals("-9999999")&&skipped.equals("0")){
if(ids){
TransitionDrawable td = (TransitionDrawable) v.getBackground();
td.startTransition(animSpeed);
}
else
v.setBackgroundResource(R.drawable.listviewitem_white_blue);
}
else {
if(ids) {
TransitionDrawable td = (TransitionDrawable) v.getBackground();
td.startTransition(animSpeed);
}
else
v.setBackgroundResource(R.drawable.listviewitem_green_blue);
}
}
问题是当我选择一行(该行变为蓝色)并向下移动列表(当该行消失时)它选择其他行。似乎它复制了行的状态并将其放在下面的列表中。
--------REAL SELECTED ROW--------
---------------------------------
| |
| |
| |
| LIST VIEW |
| |
| |
| |
|-----WRONG SELECTED ROW--------|
| |
---------------------------------
我究竟做错了什么?请帮我。