When running my Android APP on Android 7.x GUI Elements are disappearing

0

My Android APP runs fine on Android Version 5.0.2. But if i run the same APP on serveral Devices with Android 7.x The App works finde on first start but after restarting the APP some GUI Elements are disappearing. In my case 2 Images in my Listview Layout. Does anyone have a clue why this could happen? 

The images are stored in an ImageList.

I use Rad Studio 10.2 with all released Hotfixes for Android.

 

This is the Code i use to assign the images:

 

if Assigned(TmpProfile) then
        case TmpProfile.Status of
          Connected:
          begin
            //TListItemImage(ListView1.Items[I].Objects.FindDrawable('Image3')).Bitmap := ImageList1.Bitmap(TSizeF.Create(128,128), 0);
            TListItemImage(ListView1.Items[I].Objects.FindDrawable('Image3')).Bitmap := ImageList1.Bitmap(RectListViewImage3, 0);
            StatusStr := 'Connected';
          end;
          Disconnected:
          begin
            //TListItemImage(ListView1.Items[I].Objects.FindDrawable('Image3')).Bitmap := ImageList1.Bitmap(TSizeF.Create(128,128), 1);
			      TListItemImage(ListView1.Items[I].Objects.FindDrawable('Image3')).Bitmap := ImageList1.Bitmap(RectListViewImage3, 1);
            StatusStr := 'Disconnected';
          end;
          Connecting:
          begin
            //TListItemImage(ListView1.Items[I].Objects.FindDrawable('Image3')).Bitmap := ImageList1.Bitmap(TSizeF.Create(128,128), 2);
            TListItemImage(ListView1.Items[I].Objects.FindDrawable('Image3')).Bitmap := ImageList1.Bitmap(RectListViewImage3, 2);
            StatusStr := 'Connecting';
          end;
          else
          begin
            //TListItemImage(ListView1.Items[I].Objects.FindDrawable('Image3')).Bitmap := ImageList1.Bitmap(TSizeF.Create(128,128), 3);
            TListItemImage(ListView1.Items[I].Objects.FindDrawable('Image3')).Bitmap := ImageList1.Bitmap(RectListViewImage3, 3);
            StatusStr := GetErrorMessage(TmpProfile.Status);
          end;
        end;

Is there someone with similar problems?
 

Responses (4)
  • Accepted Answer

    Wednesday, November 22 2017, 08:12 AM - #Permalink
    0

    Thank you vor your advice! But unfortunately this wont work for me.

    I've implemented it a bit different:

     

    procedure TMainForm.SetListItemImage(const AListItem: TListViewItem; const ADrawableName: String; const ABitmap: TBitmap; const AOwnsBitmap: Boolean);
    var
      Drawable: TListItemDrawable;
    begin
      if Assigned(AListItem) then
      begin
        Drawable := AListItem.Objects.FindDrawable(ADrawableName);
    
        if Assigned(Drawable) and (Drawable is TListItemImage) then
        begin
          (Drawable as TListItemImage).BeginUpdate;
          try
            (Drawable as TListItemImage).Bitmap := nil;
            (Drawable as TListItemImage).OwnsBitmap := AOwnsBitmap;
            (Drawable as TListItemImage).Bitmap := ABitmap;
    
             If Assigned(ABitmap) then begin
               (Drawable as TListItemImage).Width := ABitmap.Width;
             end;
    
          finally
            (Drawable as TListItemImage).EndUpdate;
          end;
        end;
      end;
    end;

    Maybe someone has another idea?

    The reply is currently minimized Show
  • Accepted Answer

    Monday, November 20 2017, 05:06 AM - #Permalink
    0

    It was probably very complex for Embarcadero to implement TBitmap over multi-platforms and working consistently for all os versions. Although I don't use TListView, I had the same problem with images disappearing for unknown reason.

     

    AFAIK, the 'normal' way of assigning a (listview) bitmap to a TImageList is to assign the imagelist to the ListView.Images property, and then assign TListViewItem.ImageIndex to the desired index of the bitmap in the imagelist.

     

    I myself use the procedure:

     
    
    procedure AssignBitmapFromImageList(Bitmap: TBitmap; ImageList: TImageList; const BitmapName: string);
    
    var
    
      BitmapItem: TCustomBitmapItem;
    
      ImageList: TImageList;
    
     
    
      Size: TSize;
    
    begin
    
          if ImageList.BitmapItemByName(BitmapName, BitmapItem, Size) then
    
            Bitmap.Assign(BitmapItem.Bitmap)
    
    end;
    
     



    > But on Android 7 it works, too. But just for the first start. After relaunching the APP (after full close)

    > the image is not shown(On Android 5 it is), if i tap the image it is shown again.

    The reply is currently minimized Show
  • Accepted Answer

    Monday, November 20 2017, 04:20 AM - #Permalink
    0

    It will give me a SegmentationFault (Bitmap of ListView is nil). But i dont get why it works on android 5 and ":=".

    But on Android 7 it works, too. But just for the first start. After relaunching the APP (after full close) the image is not shown(On Android 5 it is), if i tap the image it is shown again.

    The reply is currently minimized Show
  • Accepted Answer

    Friday, November 17 2017, 12:59 PM - #Permalink
    0

    I'm not familiar with the way you link to TImageList, bit what will happen if you use Assign in stead of := ? So:

    TListItemImage(ListView1.Items[I].Objects.FindDrawable('Image3')).Bitmap.Assign(ImageList1.Bitmap(RectListViewImage3, 0));

     

     

    The reply is currently minimized Show
Your Reply

Please login to post a reply.........