ListView失去了职位空缺

时间:2013-01-07 12:55:17

标签: android listview garbage-collection position

我正在开发一个非常繁重的ListView应用程序,其中listitems非常繁重。当用户只有一些列表项时,一切正常,但是当用户添加更多时,一些问题就开始浮现。与listitems的交互变得更加困难,有时当单击某个项目时,用户获得触摸效果但没有效果。访问位置时(这在使用上下文操作栏http://developer.android.com/guide/topics/ui/menus.html#CAB时完成),单击会抛出NullPointerException。我很确定这是因为我的应用程序中的GC查杀资源。有没有关于如何避免这种行为的一般提示,或者可能有某种解决方法来解决这个问题?

谢谢!

编辑:

Logcat崩溃:

01-07 15:59:39.219: E/AndroidRuntime(8003): FATAL EXCEPTION: main
01-07 15:59:39.219: E/AndroidRuntime(8003): java.lang.NullPointerException
01-07 15:59:39.219: E/AndroidRuntime(8003):     at     com.simon.holocountownapp.MainActivity$1.onItemCheckedStateChanged(MainActivity.java:104)
01-07 15:59:39.219: E/AndroidRuntime(8003):     at android.widget.AbsListView$MultiChoiceModeWrapper.onItemCheckedStateChanged(AbsListView.java:6037)
01-07 15:59:39.219: E/AndroidRuntime(8003):     at android.widget.AbsListView.setItemChecked(AbsListView.java:1013)
01-07 15:59:39.219: E/AndroidRuntime(8003):     at android.widget.AbsListView.performLongPress(AbsListView.java:2807)
01-07 15:59:39.219: E/AndroidRuntime(8003):     at android.widget.AbsListView$CheckForLongPress.run(AbsListView.java:2765)
01-07 15:59:39.219: E/AndroidRuntime(8003):     at  android.os.Handler.handleCallback(Handler.java:725)
01-07 15:59:39.219: E/AndroidRuntime(8003):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-07 15:59:39.219: E/AndroidRuntime(8003):     at android.os.Looper.loop(Looper.java:137)
01-07 15:59:39.219: E/AndroidRuntime(8003):     at android.app.ActivityThread.main(ActivityThread.java:5191)
01-07 15:59:39.219: E/AndroidRuntime(8003):     at java.lang.reflect.Method.invokeNative(Native Method)
01-07 15:59:39.219: E/AndroidRuntime(8003):     at java.lang.reflect.Method.invoke(Method.java:511)
01-07 15:59:39.219: E/AndroidRuntime(8003):     at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
01-07 15:59:39.219: E/AndroidRuntime(8003):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
01-07 15:59:39.219: E/AndroidRuntime(8003):     at dalvik.system.NativeStart.main(Native Method)

第104行(在logcat中引用)调用listView.getChildAt(position),这很可能返回null,从而导致崩溃。

布局非常繁重(200多行代码),所以我将它发布到pastebin。 http://pastebin.se/KTmCA0jc

适配器:

   @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        CountdownViewHolder holder;
        CountdownItem ci = mTitle.get(position);

    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.list_item_layout, parent,
                false);

        holder = new CountdownViewHolder();
        holder.mTitle = (TextView) convertView.findViewById(R.id.textPrim);
        holder.mSubtitle = (TextView) convertView
                .findViewById(R.id.textSec);
        holder.mOverflow = (ImageButton) convertView
                .findViewById(R.id.overflow);
        holder.mInfo = (ImageButton) convertView.findViewById(R.id.info);
        holder.expand_layout = (LinearLayout) convertView
                .findViewById(R.id.expand_layout);
        holder.mExpDay = (TextView) convertView.findViewById(R.id.exp_day);
        holder.mExpSec = (TextView) convertView.findViewById(R.id.exp_sec);
        holder.mDayProgress = (ProgressBar) convertView
                .findViewById(R.id.day_progress);
        holder.mMonthProgress = (ProgressBar) convertView
                .findViewById(R.id.month_progress);
        holder.mYearText = (TextView) convertView
                .findViewById(R.id.year_text);
        holder.day_help = (TextView) convertView
                .findViewById(R.id.day_help);
        holder.month_help = (TextView) convertView
                .findViewById(R.id.month_help);

        holder.setTag(position);
        holder.setupInfoClickActions();
        holder.setupOnClickListener();
        holder.setTitle(ci.getTitle());
        holder.setSubtitle(ci.getSubtitle());
        holder.fixImageAndText(position);

        convertView.setTag(holder);
    } else {
        holder = (CountdownViewHolder) convertView.getTag();
    }

    holder.manageExpand(ci.getExpand(), ctx, position, mTitle.size());

    return convertView;
}

0 个答案:

没有答案