我的listView崩溃了。异常调度输入事件

时间:2016-04-19 13:46:18

标签: android listview android-volley

我有一个ListView(图像+文本),我从互联网上加载数据。 我扩展了ListView批处理。如果我关闭互联网并触摸视图(从ListView)而不加载图像,我会收到错误。

这是我的适配器代码:

- copy: src=/file1 dest=/destination/file1
- copy: src=/file2 dest=/destination/file2

# copy each file over that matches the given pattern
- copy: src={{ item }} dest=/destination/
  with_fileglob:
    - /files/*

这是我的Logcat。

public class AdapterListGroups extends BaseAdapter {

    private List<ItemMusicGroup> listItemsMusicGroup;
    private LayoutInflater layoutInflater;
    private LoaderData loaderData;
    final private int heightForLoad;

    public AdapterListGroups(Context context, List<ItemMusicGroup> listItemsMusicGroup, LoaderData loaderData) {
        this.listItemsMusicGroup = listItemsMusicGroup;
        this.layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.loaderData = loaderData;
        this.heightForLoad = context.getResources().getInteger(R.integer.sizeOfListView) / 2;//Параметр который определяет когда нужно подгружать данные в список
    }

    @Override
    public int getCount() {
        if ( this.listItemsMusicGroup.isEmpty() ) loaderData.extentionListItemsMusicGroup(listItemsMusicGroup, 0);//Если список пустой, подгружаем первые данне
        return this.listItemsMusicGroup.size();
    }

    @Override
    public Object getItem(int position) {
        Log.d("INFO", "getItem" + position);
        //При прокрутке смотрим нужно ли увечичвать список
        if (checkNeedExtention(position))
            loaderData.extentionListItemsMusicGroup(listItemsMusicGroup, position);
        return this.listItemsMusicGroup.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if ( view == null ) {
            view = layoutInflater.inflate(R.layout.list_item, parent, false);
        }
        ItemMusicGroup currentItemMusicGroup = getItemMusicGroup(position);
        setTextContentItem(view, currentItemMusicGroup);
        setImageContentItem(view, currentItemMusicGroup);
        return view;
    }

    //Заполняем миниатюры для картинок
    private void setImageContentItem(View view, ItemMusicGroup currentItemMusicGroup)
    {
        if ( currentItemMusicGroup.getLinkSmallImage() != null) {
            NetworkImageView networkImageView = (NetworkImageView) view.findViewById(R.id.item_networkImageView_icon);
            networkImageView.setImageUrl(currentItemMusicGroup.getLinkSmallImage(), loaderData.getImageLoader());
        }
    }
    //Заполняем данные в TextView
    private void setTextContentItem(View view, ItemMusicGroup currentItemMusicGroup)
    {
        try {

            setTextForTextView(view, R.id.item_textView_nameGroup, currentItemMusicGroup.getName());
            setTextForTextView(view, R.id.list_item_textView_countAlbum, currentItemMusicGroup.getAlbumsString());
            setTextForTextView(view, R.id.list_item_textView_countSing, currentItemMusicGroup.getTracksString());
            setTextForTextView(view, R.id.list_item_TextView_genres, currentItemMusicGroup.getGenresString());

        } catch (Exception e) {
            Log.d(getStringResource(R.string.log_tag_error, view), this.getClass().getSimpleName() + view.toString());
        }

    }

    private void setTextForTextView( View view, int resIdView, String textContent) {
        TextView nameGroup = (TextView) view.findViewById(resIdView);
        if ( textContent == null) {
            textContent = getStringResource(R.string.defaultValueParametr, view);
        }
        nameGroup.setText(textContent);
    }

    private String getStringResource(int resourseId, View view)
    {
        return view.getContext().getResources().getString(resourseId);
    }

    public ItemMusicGroup getItemMusicGroup(int position) {
        return (ItemMusicGroup) getItem(position);
    }

    private boolean checkNeedExtention(int position)
    {
        if (position >= listItemsMusicGroup.size() - heightForLoad && position < loaderData.getSizeJSONArray())
        {
            return true;
        } else return false;
    }
}

1 个答案:

答案 0 :(得分:0)

我找到了问题的答案。 也许对任何人都有用。 当我延长listItemsMusicGroup时,我必须致电notifyDataSetChanged()以获取更新ListView

public Object getItem(int position) {

    //When scrolling, let's see if it is necessary to improve the list

    if (checkNeedExtention(position)) {
        loaderData.extentionListItemsMusicGroup(listItemsMusicGroup, position);
        notifyDataSetChanged();
    }
    return this.listItemsMusicGroup.get(position);
}