相关疑难解决方法(0)

BaseAdapter导致ListView在滚动时出现故障

我遇到了一些我从一本书改编的BaseAdapter代码的问题.我一直在我的应用程序中使用此代码的变体,但只是在滚动一个长列表时才实现ListView中的项目变得混乱而不是所有元素都显示出来.

描述确切的行为非常困难,但很容易看出你是否采用了50个项目的排序列表并开始上下滚动.

class ContactAdapter extends BaseAdapter {

    ArrayList<Contact> mContacts;

    public ContactAdapter(ArrayList<Contact> contacts) {
        mContacts = contacts;
    }

    @Override
    public int getCount() {
        return mContacts.size();
    }

    @Override
    public Object getItem(int position) {
        return mContacts.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        if(convertView == null){
            LayoutInflater li = getLayoutInflater();
            view = li.inflate(R.layout.groups_item, null);
            TextView label = (TextView)view.findViewById(R.id.groups_item_title);
            label.setText(mContacts.get(position).getName());
            label = (TextView)view.findViewById(R.id.groups_item_subtitle);
            label.setText(mContacts.get(position).getNumber());
        }
        else
        {
            view = …
Run Code Online (Sandbox Code Playgroud)

android listview

9
推荐指数
2
解决办法
7693
查看次数

标签 统计

android ×1

listview ×1