android adapter getView does not repaint image on scroll and notification event
Hi I have a list and I am redrawing the image based on the setting on notification. Basically I can't figure out why the image is NOT redrawn. I see in the log that it gets set.
Odly I tried to set a textview in the same view and that works fine. What's wrong with the image? can anybody tell me?
Thank you in advance!
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
//---- if the view is null, create a new one from xml
if (convertView == null)
{
LayoutInflater layoutInflater = _context.getLayoutInflater();
convertView = layoutInflater.inflate(R.drawable.my_item_layout, parent, false);
convertView.setBackgroundResource(R.drawable.mybg);
}
CustomItem item = super.getItem(position);
if (item != null)
{
TextView title = (TextView)convertView.findViewById(R.id.titleTextView);
ImageView image1= (ImageView)convertView.findViewById(R.id.image1);
title.setText(item.getName());
if (item.getMyNotificationChangedItemState()){
image1.setImageResource(R.drawable.myimagePink); <- this does not get updated
title.setTextColor(this._context.getResources().getColor(R.color.main_text_pink));
else
{
image1.setImageResource(R.drawable.myimageBlue);
title.setTextColor(this._context.getResources().getColor(R.color.main_text_blue));
}
}
So my Blue image & text gets shown when the list gets loaded the first time. Once notification happens I first update to change the one that's currrently PINK to BLUE and then change the one that I need to update from BLUE to PINK depending on previous an开发者_JS百科d current index of the items in the list. The update is done on the activity. I can see the log prints the fact that getMyNotificationChangedItemState() is changed, and the image is being set, but I never see the change in the UI.
Why does that work for TEXTVIEW and does not work for IMAGEVIEW?
For adapters, getView() only gets called when the current view is invalidated.
Have you made sure to call invalidate() on the view in question after you make the notification?
As another sanity check, what about switching pink and blue and trying again?
精彩评论