This behavior usually indicates that your ListView uses a height of
wrap_content. It's a bad idea in general as it's pretty expensive.

On Fri, Feb 24, 2012 at 1:03 PM, Pavel Dudka <[email protected]> wrote:
> I don't think you can avoid this since getView will be called multiple
> times no matter how much items in your list. It will be called every
> time your list needs to be redrawn. So in your case I wouldn't rely on
> idea that getView() is called only once.
>
> What you can do in your situation is to maintain a List of custom
> Items in your adapter (which is already done on this stage I hope :) )
> and do a async request to fetch the name whenever you add new element
> to this list. When name is acquired - update name field in your item
> and add this item to your list (don't forget to notify changes)
> On getView() you can retrieve already downloaded "name" based on
> "position" argument.
> So idea is following:
>
> class CustomItem
> {
>    public String name;
> }
>
> Adapter:
> - ArrayList<CustomItem> list
>
> onAddNewItemToList()
> {
>    requestName(); <- this is async loader. Choose callback mechanizm
> which is more suitable for your situation
> }
>
> onNameReceived(String name)
> {
>    CustomItem newItem = new CustomItem();
>    list.add(newItem);
>    notifyDataSetChanged(); <- should be called from UI thread
> }
>
> public View getView(final int position, View convertView, ViewGroup
> parent)
> {
>    ...... <- do some preparations here
>    someTextView.setText(list.get(position).name);
> }
>
> On Feb 24, 5:14 am, vani reddy <[email protected]> wrote:
>> hi,
>>
>> ok but for a count of 1 the getview is called almost 10 times.How to avoid
>> this??
>>
>>
>>
>>
>>
>> On Fri, Feb 24, 2012 at 6:42 PM, luciofm <[email protected]> wrote:
>> > First of all, you should never do I/O (disk, networking) operations on
>> > getView() or your scrolling will be very sluggish, since they will run on
>> > the UI Thread an will block the scrolling until the request is fulfilled.
>>
>> > Lúcio Maciel
>> > [email protected]
>>
>> > On Fri, Feb 24, 2012 at 10:19, vani reddy 
>> > <[email protected]>wrote:
>>
>> >> Hey Check,
>>
>> >> @Override
>> >>     public View getView(final int position, View convertView, ViewGroup
>> >> parent) {
>>
>> >>         ViewHolder holder;
>> >>         if (convertView == null) {
>> >>             convertView = mInflater.inflate(R.layout.commentitem, null);
>>
>> >>             holder = new ViewHolder();
>> >>             holder.fbName = (TextView) convertView
>> >>                     .findViewById(R.id.reviewText);
>> >>             holder.fbName.setTypeface(fontObj_rockwell);
>> >>             holder.fbImage = (ImageView)
>> >> convertView.findViewById(R.id.fbImage);
>>
>> >>             convertView.setTag(holder);
>> >>         } else {
>> >>             holder = (ViewHolder) convertView.getTag();
>> >>         }
>>
>> >>         String profileFBURL = "http://graph.facebook.com/";
>> >>                 + m_Show.getFbids_watching().get(position) + "/picture";
>> >>         // Utility.setImageToImageView(profileFBURL, holder.fbImage);
>>
>> >>         holder.fbImage.setImageBitmap(model.getRoundedImage(profileFBURL,
>> >>                 profileFBURL, 10));
>>
>> >>         try {
>> >>             FriendInfo frndInfo = FacebookFriendAPIHandler
>> >>                     .getFacebookFriendInfo(m_Show.getFbids_watching().get(
>> >>                             position));
>> >>             holder.fbName.setText(frndInfo.getName());
>> >>         } catch (Exception e) {
>>
>> >>             e.printStackTrace();
>> >>         }
>>
>> >>         convertView.setOnClickListener(new View.OnClickListener() {
>>
>> >>             @Override
>> >>             public void onClick(View v) {
>>
>> >>                 Intent intent =new
>> >> Intent(activity,UserProfileActivity.class);
>> >>                 Bundle bundle =new  Bundle();
>>
>> >> bundle.putString("fbID",String.valueOf(m_Show.getFbids_watching().get(posit­ion)));
>> >>                 bundle.putString("class", "wall");
>> >>                 intent.putExtras(bundle);
>>
>> >>                 View view1 = WallGroup.group
>> >>                         .getLocalActivityManager()
>> >>                         .startActivity(
>> >>                                 "UserProfileActivity",
>>
>> >> intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
>> >>                         .getDecorView();
>>
>> >>                 // Again, replace the view
>> >>                 WallGroup.group.replaceView(view1);
>>
>> >>             }
>> >>         });
>> >>         return convertView;
>> >>     }
>>
>> >> --
>> >> Regards,
>> >> Vani Reddy
>>
>> >>  --
>> >> You received this message because you are subscribed to the Google
>> >> Groups "Android Developers" group.
>> >> To post to this group, send email to [email protected]
>> >> To unsubscribe from this group, send email to
>> >> [email protected]
>> >> 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 [email protected]
>> > To unsubscribe from this group, send email to
>> > [email protected]
>> > For more options, visit this group at
>> >http://groups.google.com/group/android-developers?hl=en
>>
>> --
>> Regards,
>> Vani Reddy
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en



-- 
Romain Guy
Android framework engineer
[email protected]

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

Reply via email to