tôi đang sử dụng trình xem để hiển thị từ mảng dynamicadapter.it động nhưng dữ liệu được hiển thị thay đổi bất thường khi tôi cuộn Danh sách. tôi muốn Chế độ xem danh sách của mình chỉ được điền một lần, Không phải lúc nào tôi cũng cuộn danh sách của mình. Bất kỳ đề xuất nào? Đây là Mã của tôiCách triển khai trình giữ chế độ xem?
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;
}
khi danh sách được nạp nó trông như thế này: http://i.stack.imgur.com/NrGhR.png sau khi di chuyển một số dữ liệu http://i.stack.imgur.com/sMbAD.png nó trông như thế này, và một lần nữa nếu tôi di chuyển đến đầu nó trông http://i.stack.imgur.com/0KjMa.png
PS: danh sách của tôi phải theo thứ tự chữ cái
u có thể đăng ảnh chụp màn hình đầu ra của bạn không? –
@Tilsan The Fighter: đã đăng các ảnh chụp nhanh. – Ads