【发布时间】:2011-05-07 22:22:58
【问题描述】:
我正在使用查看器从动态数组适配器显示。它可以工作,但是当我滚动列表时显示的数据会不规则地变化。我希望我的列表视图只填充一次,而不是一直当我滚动我的列表时。有什么建议吗? 这是我的代码
public View getView(int position, View convertView, ViewGroup parent) {
// A ViewHolder keeps references to children views to avoid unneccessary calls
// to findViewById() on each row.
ViewHolder holder;
// When convertView is not null, we can reuse it directly, there is no need
// to reinflate it. We only inflate a new View when the convertView supplied
// by ListView is null.
if (convertView == null) {
convertView = mInflater.inflate(R.layout.sample, null);
// Creates a ViewHolder and store references to the two children views
// we want to bind data to.
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.text);
holder.icon = (ImageView) convertView.findViewById(R.id.icon);
convertView.setTag(holder);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();
}
// Bind the data efficiently with the holder.
if(_first==true)
{
if(id<myElements.size())
{
holder.name.setText(myElements.get(id));
holder.icon.setImageBitmap( mIcon1 );
id++;
}
else
{
_first=false;
}
}
//holder.icon.setImageBitmap(mIcon2);
/*try{
if(id<myElements.size())
id++;
else
{
id--;
}
}
catch(Exception e)
{
android.util.Log.i("callRestService",e.getMessage());
}*/
return convertView;
}
static class ViewHolder {
TextView name;
ImageView icon;
}
加载列表时,它看起来像这样:http://i.stack.imgur.com/NrGhR.png 在滚动一些数据后http://i.stack.imgur.com/sMbAD.png 它看起来像这样,如果我滚动到开头,它看起来又是http://i.stack.imgur.com/0KjMa.png
P.S : 我的列表必须按字母顺序排列
【问题讨论】:
-
你能把你的输出截图贴出来吗?
-
@Tilsan The Fighter:已经发布了快照。