在我的应用程序中,我有一个Listview和我自己的ListItemStyle(自己的XML)。将List添加到ListView的我的代码如下所示:
Schueler s[] = new Schueler[]
{
new Schueler("vName", "nName", new Date()).setNoten(new Klausur(50, 4, 3)),
new Schueler("vName", "nName", new Date()).setNoten(new Klausur(100, 1, 3))
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, null);
}
Schueler s = data[position];
if(s != null)
{
TextView vName = (TextView) row.findViewById(R.id.vName);
TextView nName = (TextView) row.findViewById(R.id.nName);
LinearLayout scroll = (LinearLayout) row.findViewById(R.id.notenScroll);
HorizontalScrollView hsv = (HorizontalScrollView) row.findViewById(R.id.horizontalScrollView1);
vName.setText(s.getvName());
nName.setText(s.getnName());
for(int i = 0; i < s.getNoten().size(); i++)
{
LayoutInflater factory = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View klausur = factory.inflate(R.layout.klausur_item, null);
TextView pkt = (TextView) klausur.findViewById(R.id.pkt);
TextView note = (TextView) klausur.findViewById(R.id.note);
TextView gew = (TextView) klausur.findViewById(R.id.gew);
pkt.setText(String.valueOf(s.getNoten().get(i).getPunkte()));
note.setText(String.valueOf(s.getNoten().get(i).getNote()));
gew.setText(String.valueOf(s.getNoten().get(i).getGewichtung()));
scroll.addView(klausur);
}
}
return row;
}
随着布局一切都很好但我有一些问题,一些项目被添加到我的ListView更多次。它现在看起来像这样:
守则有什么问题?