Skip to content Skip to sidebar Skip to footer

Android Getview() Not Being Called Properly?

For some reason, the getView() method isn't being called the full amount. It should be called 10 times. But it isnt... @Override public void onCreate(Bundle savedInstanceState) {

Solution 1:

Try this way,hope this will help you to solve your problem.

public class VirtuAdapter extends BaseAdapter
    {
        private Context content;
        private ArrayList<Friend> friendList;
        public VirtuAdapter(Context context,ArrayList<Friend> friendList)
        {
            this.content = context;
            this.friendList = friendList;
        }
        @Override
        public int getCount()
        {
            return friendList.size();
        }
        @Override
        public Object getItem(int position)
        {
            return friendList.get(position);
        }
        @Override
        public long getItemId(int position)
        {
            return friendList.size();
        }
        class ViewHolder {
            TextView myTitle;
            TextView myDescription;
            ImageView myImage;
        }
        @Override
        public View getView(int position, View view, ViewGroup parent)
        {
            ViewHolder holder;
            if(view == null)
            {
                holder = new ViewHolder();
                view = LayoutInflater.from(content).inflate(R.layout.search_list_item, null, false);
                holder.myImage = (ImageView)view.findViewById(R.id.imageview);
                holder.myTitle = (TextView)view.findViewById(R.id.title);
                holder.myDescription = (TextView)view.findViewById(R.id.mutualTitle);
                view.setTag(holder);
            }
            else
            {
                holder = (ViewHolder)view.getTag();
            }
            holder.myImage.setImageResource(friendList.get(position).getImage());
            holder.myTitle.setText(friendList.get(position).getName());
            holder.myDescription.setText(friendList.get(position).getDesc());

            return view;
        }
    }

Post a Comment for "Android Getview() Not Being Called Properly?"