How to show sync failed message

前端 未结 2 1442
一向
一向 2020-12-19 21:03

I\'ve build a contacts sync adapter. It\'s all working fine but I need one more thing. If for some reason the sync does not complete successfully, I want to show a message l

2条回答
  •  不知归路
    2020-12-19 21:32

    I think what you want are Toasts

    Simple Toast:

    Toast.makeText(context, text, duration).show();
    

    text is, as you can imagine, the text you want to be displayed. duration is either Toast.LENGTH_SHORT or Toast.LENGTH_LONG (depends in how long the Toast sahll be visible)

    More complicated approach with picture in the toast: (sync_toast_lo.xml)

    
      
    
      
      
    
      
      
    
    

    And in your code:

    LayoutInflater inflater = getLayoutInflater();
    View view = inflater.inflate(R.layout.Sync_toast_lo,
                                   (ViewGroup) findViewById(R.id.SynctoastLayout));
    
    Toast toast = new Toast(this);
    toast.setView(view);
    toast.show();
    

提交回复
热议问题