0

I need to load only the second item's image from a URL. I've searched for libraries and methods to make lists with URL images and text, but i only need the second item's image to be loaded.

public void prepareArrayLits()
{
    menuItemList = new ArrayList<Object>();

    AddObjectToList(R.drawable.icon_door, "Pet Open");
    AddObjectToList(R.drawable.icon_profile_small, GlobalData.fullname);
    AddObjectToList(R.drawable.icon_messages, "Messages");
    AddObjectToList(R.drawable.icon_people, "People");
    AddObjectToList(R.drawable.icon_settings, "Settings");
    AddObjectToList(R.drawable.icon_logout, "Log Out");
}

I wouldn't like to change the adapter, so what if i could change the second item's image after the list was made. Is there any way i could do this?

other items images' from list cannot be loaded from url


@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return menuItemList.get(position);
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub

    ViewHolder holder;
    if(convertView==null)
    {
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.menu_drawer_left, null);

        holder.listMenuIcon = (ImageView) convertView.findViewById(R.id.ic_menu);
        holder.listMenuText = (TextView) convertView.findViewById(R.id.txt_menu);

        convertView.setTag(holder);
    }
    else
        holder=(ViewHolder)convertView.getTag();

    MenuItemBean bean = (MenuItemBean) menuItemList.get(position);



    holder.listMenuIcon.setImageResource(bean.getMenuIcon());
    holder.listMenuText.setText(bean.getMenuText());


    return convertView;
}

If the count starts from 0, i would like to change the item with id 1. How do i change it?

Filip Luchianenco
  • 6,912
  • 9
  • 41
  • 63
  • 1
    Why not change the adapter? I think you should change your adapter because of this: If you have 100 items in your list and maybe 20 need to load from a network source. How would you tell what item is currently visible in the list? Because loading all 20 while only 2 are visible is memory waste if you ask me. Imagine what would happen if you have 2000 items in you list that need to be loaded from a network source? It would kill your application. An adapter can automate inflating and loading resources for you in a very easy and memory friendly way. I would say: you SHOULD CHANGE your adapter. – Rolf ツ Nov 14 '13 at 11:23
  • Take a look at this question: http://stackoverflow.com/questions/541966/how-do-i-do-a-lazy-load-of-images-in-listview – Rolf ツ Nov 14 '13 at 11:25
  • i have other lists in other places, there may be an undefined number of items; i would do in the correct way there. Here is the menu, i only have these items here, it will not get bigger. I want to change the profile picture, which is downloaded from the server. but if i change the adapter would i be able to load others from drawable? – Filip Luchianenco Nov 14 '13 at 11:29
  • I would say prepare your adapter with dummy images, than set it to the list and start loading the images needed. When you got the images renew the list data using the getItem method from your adapter. Than invalidate the list using the notifyDataSetChanged method from your adapter so your view will be updated. If you don't get it I will post an example code without the network loading. – Rolf ツ Nov 14 '13 at 11:42
  • I updated the questions with methods that i have in my Custom Adapter. How do i write something like: 'if(itemID == 1) { set image myBitmapImage }' p.s. I will load the image from URL before making the list – Filip Luchianenco Nov 14 '13 at 12:29
  • Can't you store the Bitmap image in the MenuItemBean? Or isn't that a custom object? If it is you don't need to write an if statement but just update the MenuItemBean with the new image and than invalidate the view. – Rolf ツ Nov 14 '13 at 12:37

0 Answers0