Below is my code:

AllBuddyListAdapter.class:

        private class AllBuddyListAdapter extends BaseAdapter {
                public List<BuddyTO> allBuddyList;

                public AllBuddyListAdapter(Context con, List<BuddyTO> 
allBuddyList){
                        this.allBuddyList = allBuddyList;
                }
                @Override
                public int getCount() {
                        return this.allBuddyList.size();
                }

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

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

                @Override
                public View getView(int position, View convertView, ViewGroup
parent) {
                        BuddyTO buddy = allBuddyList.get(position);
                        BuddyListView holder = null;

                        try {
                                if (convertView == null) {
                                        holder = new BuddyListView();
                                        convertView =
getLayoutInflater().inflate(R.layout.buddy_list_layout, parent,
false);
                                        holder.titleText = (TextView)
convertView.findViewById(R.id.listTitle);
                                        holder.distText = (TextView)
convertView.findViewById(R.id.distText);
                                        holder.avatar =(ImageView) 
convertView.findViewById(R.id.avatar);
                                        LayoutInflater inflater = 
(LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                                        holder.v2 = 
inflater.inflate(R.layout.buddy_list_popup,null);
                                        holder.ballonName = (TextView)
holder.v2.findViewById(R.id.balloon_item_snippet);
                                        holder.buddyImage = (ImageView)
holder.v2.findViewById(R.id.buddyImg);
                                        holder.btnIM = (ImageView)
holder.v2.findViewById(R.id.im_button);
                                        holder.btnSms = (ImageView)
holder.v2.findViewById(R.id.sms_button);
                                        holder.groupBtn = (ImageView)
holder.v2.findViewById(R.id.edit_button);
                                        holder.btnCall = (ImageView)
holder.v2.findViewById(R.id.call_button);
                                        holder.btnNudge = (ImageView)
holder.v2.findViewById(R.id.nudge_button);
                                        holder.popupLinear = (LinearLayout)
holder.v2.findViewById(R.id.balloon_main_layout);
                                        holder.linear = (ImageView)
holder.v2.findViewById(R.id.close_button);
                                        holder.drawable =
convertView.getContext().getResources().getDrawable(R.drawable.avatar);
                                        holder.smsView = 
inflater.inflate(R.layout.sms,holder.smsLayout);
                                        holder.backBtn = (Button)
holder.smsView.findViewById(R.id.btnBack);
                                        holder.unblockBtn = (ImageView)
convertView.findViewById(R.id.btnUnblock);
                                        holder.blockBtn = (ImageView)
convertView.findViewById(R.id.btnBlock);
                                        holder.unshareBtn = (ImageView)
convertView.findViewById(R.id.btnUnShare);
                                        holder.shareBtn = (ImageView)
convertView.findViewById(R.id.btnShare);
                                        holder.status = (ImageView)
convertView.findViewById(R.id.status);
                                        holder.userGroup = (TextView)
convertView.findViewById(R.id.listTitleGroup);
                                        holder.buddyLineView = convertView;
                                        convertView.setTag(holder);
                                } else {
                                        holder = 
(BuddyListView)convertView.getTag();
                                }



                                if (buddy.isShareLocToBuddy()) {
                                        
holder.unshareBtn.setVisibility(View.VISIBLE);
                                        
holder.shareBtn.setVisibility(View.GONE);
                                } else {
                                        
holder.unshareBtn.setVisibility(View.GONE);
                                        
holder.shareBtn.setVisibility(View.VISIBLE);
                                }

                                if (!buddy.isBlockBuddy()) {
                                        
holder.unblockBtn.setVisibility(View.VISIBLE);
                                        
holder.blockBtn.setVisibility(View.GONE);
                                } else {
                                        
holder.unblockBtn.setVisibility(View.GONE);
                                        
holder.blockBtn.setVisibility(View.VISIBLE);
                                }

                                Drawable temp;
                                if (buddy.isOnLine()) {
                                        temp = 
getResources().getDrawable(R.drawable.green_dot);
                                } else {
                                        if(buddy.isRegisteredBuddy()){
                                                temp = 
getResources().getDrawable(R.drawable.red_dot);
                                        }else{
                                                temp = 
getResources().getDrawable(R.drawable.grey_dot);
                                        }
                                }
                                holder.status.setImageDrawable(temp);

                                if (!buddy.isRegisteredBuddy()) {
                                        
holder.unblockBtn.setVisibility(View.GONE);
                                        
holder.blockBtn.setVisibility(View.GONE);
                                        
holder.unshareBtn.setVisibility(View.GONE);
                                        
holder.shareBtn.setVisibility(View.GONE);
                                }
                                setBuddyLayout(holder, buddy);
                        } catch (Throwable e) {
                                e.printStackTrace();
                                Log.e("Error", e.toString());
                        }

                        return convertView;
                }

        }




MyExpandableListAdapter.class:

public class MyExpandableListAdapter extends BaseExpandableListAdapter
{
                // Sample data set. children[i] contains the children 
(String[]) for
                // groups[i].
                private List<String> groups;
                private List<List<BuddyTO>> childs;
                private LayoutInflater inflater;

                public MyExpandableListAdapter(Context con) {
                        this.groups = new ArrayList<String>();
                        this.childs = new ArrayList<List<BuddyTO>>();

                        this.inflater = (LayoutInflater) getApplicationContext()
                                        
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                }

                public void update(List<String> group, List<List<BuddyTO>>
child,boolean refresh) {
                        this.groups = group;
                        this.childs = child;
                        if(refresh)
                                notifyDataSetChanged();

                }

                public int getRowId(int groupPosition) {
                        return groupPosition;
                }

                public Object getChild(int groupPosition, int childPosition) {
                        return childs.get(groupPosition).get(childPosition);
                }

                public long getChildId(int groupPosition, int childPosition) {
                        return childPosition;
                }

                public int getChildrenCount(int groupPosition) {
                        return childs.get(groupPosition).size();
                }

                public View getChildView(final int groupPosition,
                                final int childPosition, boolean isLastChild, 
View convertView,
                                ViewGroup parent) {
                        BuddyListView holder = null;

                        try {
                                if (convertView == null) {
                                        holder = new BuddyListView();
                                        convertView =
getLayoutInflater().inflate(R.layout.buddy_list_layout, parent,
false);
                                        holder.titleText = (TextView)
convertView.findViewById(R.id.listTitle);
                                        holder.distText = (TextView)
convertView.findViewById(R.id.distText);
                                        holder.avatar =(ImageView) 
convertView.findViewById(R.id.avatar);
                                        LayoutInflater inflater = 
(LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                                        holder.v2 = 
inflater.inflate(R.layout.buddy_list_popup,null);
                                        holder.ballonName = (TextView)
holder.v2.findViewById(R.id.balloon_item_snippet);
                                        holder.buddyImage = (ImageView)
holder.v2.findViewById(R.id.buddyImg);
                                        holder.btnIM = (ImageView)
holder.v2.findViewById(R.id.im_button);
                                        holder.btnSms = (ImageView)
holder.v2.findViewById(R.id.sms_button);
                                        holder.groupBtn = (ImageView)
holder.v2.findViewById(R.id.edit_button);
                                        holder.btnCall = (ImageView)
holder.v2.findViewById(R.id.call_button);
                                        holder.btnNudge = (ImageView)
holder.v2.findViewById(R.id.nudge_button);
                                        holder.popupLinear = (LinearLayout)
holder.v2.findViewById(R.id.balloon_main_layout);
                                        holder.linear = (ImageView)
holder.v2.findViewById(R.id.close_button);
                                        holder.drawable =
convertView.getContext().getResources().getDrawable(R.drawable.avatar);
                                        holder.smsView = 
inflater.inflate(R.layout.sms,holder.smsLayout);
                                        holder.backBtn = (Button)
holder.smsView.findViewById(R.id.btnBack);
                                        holder.unblockBtn = (ImageView)
convertView.findViewById(R.id.btnUnblock);
                                        holder.blockBtn = (ImageView)
convertView.findViewById(R.id.btnBlock);
                                        holder.unshareBtn = (ImageView)
convertView.findViewById(R.id.btnUnShare);
                                        holder.shareBtn = (ImageView)
convertView.findViewById(R.id.btnShare);
                                        holder.status = (ImageView)
convertView.findViewById(R.id.status);
                                        holder.userGroup = (TextView)
convertView.findViewById(R.id.listTitleGroup);
                                        holder.buddyLineView = convertView;
                                        convertView.setTag(holder);
                                } else {
                                        holder = 
(BuddyListView)convertView.getTag();
                                }

                                final BuddyTO dto = (BuddyTO) 
getChild(groupPosition,
                                                childPosition);




                                if (dto.isShareLocToBuddy()) {
                                        
holder.unshareBtn.setVisibility(View.VISIBLE);
                                        
holder.shareBtn.setVisibility(View.GONE);
                                } else {
                                        
holder.unshareBtn.setVisibility(View.GONE);
                                        
holder.shareBtn.setVisibility(View.VISIBLE);
                                }

                                if (!dto.isBlockBuddy()) {
                                        
holder.unblockBtn.setVisibility(View.VISIBLE);
                                        
holder.blockBtn.setVisibility(View.GONE);
                                } else {
                                        
holder.unblockBtn.setVisibility(View.GONE);
                                        
holder.blockBtn.setVisibility(View.VISIBLE);
                                }

                                if (filterNumber == 2) {
                                        if (dto.isOnLine()) {
                                                Drawable temp = 
getResources().getDrawable(
                                                                
R.drawable.green_dot);
                                                
holder.status.setImageDrawable(temp);
                                        } else{
                                                if (dto.isRegisteredBuddy()) {
                                                        Drawable temp = 
getResources().getDrawable(
                                                                        
R.drawable.red_dot);
                                                        
holder.status.setImageDrawable(temp);
                                                } else{
                                                        
holder.unblockBtn.setVisibility(View.GONE);
                                                        
holder.blockBtn.setVisibility(View.GONE);
                                                        
holder.unshareBtn.setVisibility(View.GONE);
                                                        
holder.shareBtn.setVisibility(View.GONE);
                                                        Drawable temp = 
getResources().getDrawable(
                                                                        
R.drawable.grey_dot);
                                                        
holder.status.setImageDrawable(temp);
                                                }
                                        }

                                } else {
                                        Drawable temp;
                                        BuddyTO buddy;
                                        buddy = 
childs.get(groupPosition).get(childPosition);
                                        if(buddy.isOnLine()){
                                                temp = 
getResources().getDrawable(R.drawable.green_dot);
                                        }else{
                                                if(buddy.isRegisteredBuddy()){
                                                        temp = 
getResources().getDrawable(R.drawable.red_dot);
                                                }else{
                                                        temp = 
getResources().getDrawable(R.drawable.grey_dot);
                                                }
                                        }
                                        holder.status.setImageDrawable(temp);
                                }

                                if (!dto.isRegisteredBuddy()) {
                                        
holder.unblockBtn.setVisibility(View.GONE);
                                        
holder.blockBtn.setVisibility(View.GONE);
                                        
holder.unshareBtn.setVisibility(View.GONE);
                                        
holder.shareBtn.setVisibility(View.GONE);
                                }
                                setBuddyLayout(holder, dto);
                        } catch (Throwable e) {
                                e.printStackTrace();
                                Log.e("Error", e.toString());
                        }
                        return convertView;
                }



setBuddyLayout.class:

public void setBuddyLayout(final BuddyListView holder, final BuddyTO
dto) {
                Log.e("setBuddyLayout", dto.getBuddyName() + "|" +
dto.getDistanceWithBuddy());
                try{

                final String name = URLDecoder.decode(dto.getBuddyName());
                final String phone = dto.getBuddyNumber();
                holder.titleText.setText(name);
                holder.distText.setText(dto.getDistanceWithBuddy());

                if (dto.isFriendGroup()) {
                        holder.userGroup.setText("Friends");
                } else if (dto.isFamilyGroup()) {
                        holder.userGroup.setText("Family");
                } else if (dto.isWorkGroup()) {
                        holder.userGroup.setText("Work");
                } else if (dto.isOtherGroup()) {
                        holder.userGroup.setText("Others");
                }


                final String avatarURL = con_.getString(R.string.avatar_server) 
+
phone+ ".jpg";

                        Drawable drawable = null;
                                try {

                                        if (dto.isRegisteredBuddy() &&
drawableManager.containDrawable(avatarURL,phone)) {
        
drawableManager.fetchDrawableOnThread(avatarURL,phone,holder.avatar,null,null,con_);
                                        }else{
                                                drawable = 
con_.getResources().getDrawable(R.drawable.avatar);
                                                
holder.avatar.setImageDrawable(drawable);

                                        }

                                } catch (Throwable e) {
                                        drawable = 
con_.getResources().getDrawable(R.drawable.avatar);
                                        
holder.avatar.setImageDrawable(drawable);

                        }

        }catch(Throwable tr){
                Log.e("Throwable",tr.toString());
        }
        }




buddy_list_layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/linearTab"
        android:background="#ffffff" xmlns:android="http://
schemas.android.com/apk/res/android"
        android:orientation="horizontal" android:layout_width="fill_parent"

        android:layout_height="wrap_content">

        <ImageView android:layout_width="wrap_content" android:src="@drawable/
grey_dot"
                android:background="#ffffff" 
android:layout_height="wrap_content"
android:id="@+id/status"
                android:layout_gravity="center_vertical"
android:layout_marginLeft="5dip"/>

        <ImageView android:layout_width="50dip" android:src="@drawable/
avatar"
                android:background="#ffffff" android:layout_height="50dip"
android:id="@+id/avatar"
                android:layout_margin="5dip"/>

        <LinearLayout android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:gravity="center_vertical"
                android:layout_gravity="center_vertical"
                android:layout_weight="1">
                <TextView android:layout_width="fill_parent" android:id="@+id/
listTitle"
                        android:layout_marginLeft="5sp"
android:layout_height="wrap_content" android:text=""
                        android:textColor="#000000"
android:layout_gravity="center_vertical"
                        android:textStyle="bold" android:textSize="15dip"/>

                <TextView android:layout_width="fill_parent" android:id="@+id/
listTitleGroup"
                        android:layout_marginLeft="5sp"
android:layout_height="wrap_content"
                        android:textColor="#000000"
android:layout_gravity="center_vertical"
                        android:paddingTop="5dip" android:textSize="12dip" 
android:text=""/
>
        </LinearLayout>

        <TextView android:layout_width="wrap_content" android:id="@+id/
distText"
                android:layout_height="wrap_content" 
android:paddingRight="20dip"
                android:text="N.A" android:textColor="#000000"
android:layout_gravity="center_vertical" />

        <ImageView android:layout_width="wrap_content" android:id="@+id/
btnUnShare"
                android:layout_marginRight="20dip"
android:layout_height="wrap_content"
                android:background="@drawable/green_tick"
android:layout_gravity="center_vertical"
                android:visibility="gone" />

        <ImageView android:layout_width="wrap_content" android:id="@+id/
btnShare"
                android:layout_marginRight="20dip"
android:layout_height="wrap_content"
                android:background="@drawable/checkbox"
android:layout_gravity="center_vertical" />
        <ImageView android:layout_width="wrap_content"
                android:layout_marginRight="20dip" android:id="@+id/btnBlock"
                android:paddingRight="10dip" 
android:layout_height="wrap_content"
                android:background="@drawable/checkbox"
android:layout_gravity="center_vertical" />

        <ImageView android:layout_width="wrap_content"
                android:layout_marginRight="20dip" android:id="@+id/btnUnblock"
                android:paddingRight="15dip" 
android:layout_height="wrap_content"
                android:background="@drawable/red_tick" 
android:visibility="gone"
                android:layout_gravity="center_vertical" />

</LinearLayout>


the avatar will flick once i call notifyDataSetChanged().

Thanks a lot.

On Feb 26, 9:01 am, Justin Anderson <magouyaw...@gmail.com> wrote:
> We can help better if you post your code...
> On Feb 24, 2011 10:01 PM, "Sao Kim Beng" <kbsa...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi All,
> > i have a listview/ExpandableListView contain Imageview and some text.
> > I facing a problem when there is a new entry in and i try to update
> > the list , after i try to refresh the BaseAdapter/
> > BaseExpandableListAdapter by calling notifyDataSetChanged, every
> > imageview will flicking once.
>
> > It like loading all the image again from top to bottom again, is it
> > any way to just update those data and show to the user without
> > flicking?
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to