开发者

Android: 2 toasts same time

Ok, I have 1 custom toast (xml layout) and it works great:

    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup) findViewById(R.id.toast_layout));
    ImageView image = (ImageView) layout.findViewById(R.id.logo);        
    image.setImageResource(R.drawable.logo);
    title = (TextView) layout.findViewById(R.id.title);        
    txt = (TextView) layout.findViewById(R.id.text);
    toast = new Toast(appContext);
    toast.setGravity(Gravity.FILL_HORIZONTAL|Gravity.BOTTOM, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);        

But when I try to make 2nd one same way I get error "Source not found" which doesn't really tell me anything about what's wrong.

开发者_如何学JAVA    LayoutInflater infl = getLayoutInflater();
    View lay = infl.inflate(R.layout.toast_arrows, (ViewGroup) findViewById(R.id.toast_lay));                        
    toastarrows = new Toast(appContext);
    toastarrows.setGravity(Gravity.FILL_HORIZONTAL|Gravity.CENTER, 0, 0);
    toastarrows.setDuration(Toast.LENGTH_SHORT);
    toastarrows.setView(lay);                
    toastarrows.show();

I'd like those 2 toasts to appear almost same time in different places of the screen. Anyone can tell me please what's wrong with this code?


you are sure that you can show 2 Toast at the same time? i'm not sure about this, i tried it but i can display only one Toast. you have tried to show only the second one?


It seems that if you do really create two toasts at the sametime they will still be shown one after another in the same place. So I think your stuggling's vain.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜