我在自定义列表视图中遇到问题,我在 db 的文本视图中显示了 10 行值。当我滚动列表时,项目被重复。考虑到我有从 1 到 10 的行数。如果我滚动它,这些行将重复为 1、2、3、4、5、1、6、7、8、9、2、3 等。再次显示相同的值。我不知道为什么会这样。如果我删除 5 个项目并禁用滚动,那么它没有任何问题。在启用滚动的情况下添加更多行数会出现此问题。
private class ItemLayoutListViewAdapter extends BaseAdapter {
Context context;
Hold myHold;
String[] TableNo, MachineId, ItemName, Quantity, Progress, Timer;
private ItemLayoutListViewAdapter(Context context, String[] aTableNo, String[] aMachineId, String[] aItemName, String[] aQuantity,
String[] aProgress, String[] aTimer) {
this.TableNo = aTableNo;
this.MachineId = aMachineId;
this.ItemName = aItemName;
this.Quantity = aQuantity;
this.Progress = aProgress;
this.Timer = aTimer;
this.context = context;
}
private class Hold {
TextView[] tvItemLayoutListItems = new TextView[6];
ImageButton ibItemCustomization, ibCorrect, ibWrong;
ImageButton[] ibUpDownArrow = new ImageButton[2];
Button bnProgress;
Chronometer chTimer;
}
@Override
public int getCount() {
return TableNo.length;
}
@Override
public Object getItem(int arg0) {
return arg0;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(final int arg0, View arg1, ViewGroup arg2) {
if (arg1 == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
arg1=inflater.inflate(R.layout.kitchen_item_list_view_layout,null);
myHold = new Hold();
int[] tvItemLayoutListItemsIds = { R.id.tvTableNo,
R.id.tvMachineId, R.id.tvItemName, R.id.tvQuantity,R.id.tvTimer, R.id.tvDummyItemName };
int[] ibUpDownArrowIds = { R.id.ibArrowUp, R.id.ibArrowDown };
for(int itvItemLayoutListItemsIdsCtr = 0; itvItemLayoutListItemsIdsCtr < tvItemLayoutListItemsIds.length;itvItemLayoutListItemsIdsCtr++) {
myHold.tvItemLayoutListItems[itvItemLayoutListItemsIdsCtr] = (TextView) arg1
.findViewById(tvItemLayoutListItemsIds[itvItemLayoutListItemsIdsCtr]);
}
myHold.chTimer = (Chronometer) arg1.findViewById(R.id.chTimer);
myHold.bnProgress = (Button) arg1.findViewById(R.id.bnProgress);
myHold.tvItemLayoutListItems[0].setText(TableNo[arg0]);
myHold.tvItemLayoutListItems[1].setText(MachineId[arg0]);
myHold.tvItemLayoutListItems[2].setText(ItemName[arg0]);
myHold.tvItemLayoutListItems[3].setText(Quantity[arg0]);
myHold.tvItemLayoutListItems[4].setText(Timer[arg0]);
myHold.ibCorrect = (ImageButton) arg1
.findViewById(R.id.ibCorrect);
myHold.ibCorrect.setTag(myHold);
myHold.ibCorrect.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Hold Itemholder;
Itemholder = (Hold) arg0.getTag();
if (Itemholder.tvItemLayoutListItems[5].getText()
.equals("Orange")) {
Itemholder.tvItemLayoutListItems[2]
.setBackground(context.getResources()
.getDrawable(
R.drawable.textview_green));
} else {
Itemholder.tvItemLayoutListItems[2]
.setBackground(context.getResources()
.getDrawable(
R.drawable.textview_orange));
;
Itemholder.tvItemLayoutListItems[5]
.setText("Orange");
}
}
});
myHold.ibWrong = (ImageButton) arg1.findViewById(R.id.ibWrong);
myHold.ibWrong.setTag(myHold);
myHold.ibWrong.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Hold Itemholder;
Itemholder = (Hold) arg0.getTag();
Itemholder.tvItemLayoutListItems[2]
.setBackground(context
.getResources()
.getDrawable(R.drawable.textview_border));
}
});
myHold.ibItemCustomization = (ImageButton) arg1
.findViewById(R.id.ibItemCustomization);
myHold.ibItemCustomization
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
new item_customization(context).CustomizeItem();
}
});
for (int iibUpDownArrowIdsCtr = 0; iibUpDownArrowIdsCtr < ibUpDownArrowIds.length; iibUpDownArrowIdsCtr++) {
myHold.ibUpDownArrow[iibUpDownArrowIdsCtr] = (ImageButton) arg1
.findViewById(ibUpDownArrowIds[iibUpDownArrowIdsCtr]);
myHold.ibUpDownArrow[iibUpDownArrowIdsCtr].setTag(myHold);
}
myHold.ibUpDownArrow[0]
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
IncDecTimer(arg0,true);
}
});
myHold.ibUpDownArrow[1]
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
IncDecTimer(arg0,false);
}
});
myHold.chTimer.setTag(myHold);
myHold.tvItemLayoutListItems[4].setTag(myHold);
myHold.chTimer.setBase(1000);
myHold.chTimer.start();
myHold.chTimer
.setOnChronometerTickListener(new OnChronometerTickListener() {
@Override
public void onChronometerTick(Chronometer arg0) {
final Hold Timerholder;
Timerholder = (Hold) arg0.getTag();
String[] sTimer = Timerholder.tvItemLayoutListItems[4]
.getText().toString().split(":");
int iMin, iSec, iSecValue;
iMin = Integer.parseInt(sTimer[0]);
iSec = Integer.parseInt(sTimer[1]);
if (iSec == 0) {
iMin = iMin - 1;
if (iMin == -1) {
Timerholder.tvItemLayoutListItems[4]
.setText("00:00");
Timerholder.chTimer.stop();
}
iSecValue = 60;
} else {
iSecValue = iSec;
}
iSecValue = iSecValue - 1;
String sMin, sSec;
if (iMin < 10) {
sMin = "0";
} else {
sMin = "";
}
if (iSecValue < 10) {
sSec = "0";
} else {
sSec = "";
}
if (iMin > -1) {
Timerholder.tvItemLayoutListItems[4].setText(sMin
.concat(String.valueOf(iMin))
.concat(":").concat(sSec)
.concat(String.valueOf(iSecValue)));
}
}
});
arg1.setTag(myHold);
} else {
arg1.getTag();
}
return arg1;
}
请帮帮我。如果您需要代码,请告诉我。我保留了基本的自定义列表视图,其中包含文本视图。