我有一个嵌套数组要显示在我的 Listview 中。ListView 的每一行都会有一个水平 LinerLayout 到 HorizontalScrollView。
目前我正在使用 ViewHolder 模式并在 ListView 的 getView 方法中动态地将视图添加到 LinerLayout。
问题是我滚动时列表视图滞后..
这是我的自定义适配器类
public class ChannelArrayAdapter extends ArrayAdapter<Kanal> {
Context context;
List<Kanal> list;
List<Program> pList;
LayoutInflater inflator;
public ChannelArrayAdapter(Context context, List<Kanal> lis) {
super(context, R.layout.channels, lis);
// TODO Auto-generated constructor stub
this.list = lis;
this.context = context;
}
static class ViewHolder {
ImageView imageView;
LinearLayout l;
}
static class ProgramHolder {
TextView programAdi;
TextView programSaati;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
if (convertView == null) {
inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflator.inflate(R.layout.channels, parent, false);
viewHolder.imageView = (ImageView) convertView.findViewById(R.id.imageView1);
viewHolder.l = (LinearLayout) convertView.findViewById(R.id.yayinAkisiLayout);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder)convertView.getTag();
viewHolder.l.removeAllViews();
}
final Kanal kanal = list.get(position);
pList = kanal.getKanalProgramListesi();
viewHolder.imageView.setImageResource(kanal.getResourcesIkonKanal());
for (Program p : pList) {
View v = new View(context);
v.setId(position);
ProgramHolder pHolder = new ProgramHolder();
v = inflator.inflate(R.layout.programs, null);
pHolder.programSaati = (TextView) v.findViewById(R.id.psaati);
pHolder.programAdi = (TextView)v.findViewById(R.id.pname);
pHolder.programAdi.setText(p.getProgramAdi());
pHolder.programSaati.setText(p.getProgramBaslangic());
v.setTag(pHolder);
viewHolder.l.addView(v);
}
return convertView;
}
}