android-BaseAdapter中的notifyDataSetChanged()

android-BaseAdapter中的notifyDataSetChanged(),第1张

概述这是我的代码,在这里我试图从Arraylist中删除该项目,并尝试使用notifyDataSetChanged更新布局项目.publicclassGroupContactListingAdapterextendsBaseAdapter{privateLayoutInflatermInflater;privateArrayList<ContactListDto>groupListDto=newArrayLis

这是我的代码,在这里我试图从ArrayList中删除该项目,并尝试使用notifyDataSetChanged更新布局项目.

public class GroupContactListingAdapter extends BaseAdapter {    private LayoutInflater mInflater;    private ArrayList<ContactListDto> groupListDto = new ArrayList<ContactListDto>();    private Activity context;    public static ArrayList<String> selectList;    @OverrIDe    public voID notifyDataSetChanged() {        super.notifyDataSetChanged();    }    /**     * Assigning the parameter     *      * @param mContext1     *            Getting the context of the class     * @param contactList     *            List to be display     * @param value     *            if 0 all, if 1 unblocked and 2 blocked     * @param isContactList     *            if 1 then contact List and if 0 search contact List     */    public GroupContactListingAdapter(Activity mContext1,            ArrayList<ContactListDto> contactList) {        this.context = mContext1;        this.mInflater = (LayoutInflater) mContext1                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);        if (this.groupListDto != null) {            this.groupListDto.clear();        }        this.groupListDto = contactList;        selectList = new ArrayList<String>();    }    @OverrIDe    public int getCount() {        return groupListDto.size();    }    @OverrIDe    public Object getItem(int position) {        return groupListDto.get(position);    }    @OverrIDe    public long getItemID(int arg0) {        return arg0;    }    @OverrIDe    public VIEw getVIEw(final int position, VIEw convertVIEw, VIEwGroup arg2) {        final VIEwHolder vIEwHolder;        if (convertVIEw == null) {            convertVIEw = mInflater.inflate(R.layout.group_Listing_item, null);            vIEwHolder = new VIEwHolder();            vIEwHolder.nameTextVIEw = (TextVIEw) convertVIEw                    .findVIEwByID(R.ID.group_name);            vIEwHolder.relative = (relativeLayout) convertVIEw                    .findVIEwByID(R.ID.group_layout);            vIEwHolder.deleteContacts = (button) convertVIEw                    .findVIEwByID(R.ID.btn_group_contact_delete);        } else {            vIEwHolder = (VIEwHolder) convertVIEw.getTag();        }        vIEwHolder.deleteContacts.setVisibility(VIEw.VISIBLE);        vIEwHolder.deleteContacts                .setonClickListener(new VIEw.OnClickListener() {                    @OverrIDe                    public voID onClick(VIEw v) {                        Helper.printLogD(" deleting position is " + position);                        selectList.add(groupListDto.get(position)                                .getContactID());                        groupListDto.remove(groupListDto.get(position));                        notifyDataSetChanged();                    }                });        vIEwHolder.nameTextVIEw.setText(groupListDto.get(position)                .getContactFullname());        if (position % 2 == 0) {            vIEwHolder.relative.setBackgroundcolor(context.getResources()                    .getcolor(R.color.white));        } else {            vIEwHolder.relative.setBackgroundcolor(context.getResources()                    .getcolor(R.color.List_even_color));        }        return convertVIEw;    }

发生以下错误

12-18 11:43:01.895: E/ListVIEw(24434): null12-18 11:43:01.895: E/ListVIEw(24434): java.lang.NullPointerException12-18 11:43:01.895: E/ListVIEw(24434):  at com.hazemedia.stewdent.clIEnt.androID.ui.adapter.GroupContactListingAdapter$VIEwHolder.access(GroupContactListingAdapter.java:133)12-18 11:43:01.895: E/ListVIEw(24434):  at com.hazemedia.stewdent.clIEnt.androID.ui.adapter.GroupContactListingAdapter.getVIEw(GroupContactListingAdapter.java:94)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.Widget.AbsListVIEw.obtainVIEw(AbsListVIEw.java:1428)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.Widget.ListVIEw.makeAndAddVIEw(ListVIEw.java:1801)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.Widget.ListVIEw.fillSpecific(ListVIEw.java:1339)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.Widget.ListVIEw.layoutChildren(ListVIEw.java:1625)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.Widget.AbsListVIEw.onLayout(AbsListVIEw.java:1279)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.vIEw.VIEw.layout(VIEw.java:7321)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.Widget.relativeLayout.onLayout(relativeLayout.java:912)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.vIEw.VIEw.layout(VIEw.java:7321)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.Widget.FrameLayout.onLayout(FrameLayout.java:338)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.vIEw.VIEw.layout(VIEw.java:7321)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.Widget.FrameLayout.onLayout(FrameLayout.java:338)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.vIEw.VIEw.layout(VIEw.java:7321)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.vIEw.VIEwRoot.performTraversals(VIEwRoot.java:1217)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.vIEw.VIEwRoot.handleMessage(VIEwRoot.java:1995)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.os.Handler.dispatchMessage(Handler.java:99)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.os.Looper.loop(Looper.java:150)12-18 11:43:01.895: E/ListVIEw(24434):  at androID.app.ActivityThread.main(ActivityThread.java:4389)12-18 11:43:01.895: E/ListVIEw(24434):  at java.lang.reflect.Method.invokeNative(Native Method)12-18 11:43:01.895: E/ListVIEw(24434):  at java.lang.reflect.Method.invoke(Method.java:507)12-18 11:43:01.895: E/ListVIEw(24434):  at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)12-18 11:43:01.895: E/ListVIEw(24434):  at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:607)12-18 11:43:01.895: E/ListVIEw(24434):  at dalvik.system.NativeStart.main(Native Method)

解决方法:

出现此问题是因为我没有在convertVIEw实例中标记vIEwHolder.

convertVIEw .setTag(vIEwHolder);
总结

以上是内存溢出为你收集整理的android-BaseAdapter中的notifyDataSetChanged()全部内容,希望文章能够帮你解决android-BaseAdapter中的notifyDataSetChanged()所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1086157.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存