【问题标题】:How to show messages in alertdialog randomly如何在警报对话框中随机显示消息
【发布时间】:2012-12-16 19:02:17
【问题描述】:

我正在使用 AlertDialog 显示任何消息和链接,我使用此代码。但我想在每个动作中随机显示不同的消息(链接)。那可能吗?如果是的话,你能给我这个示例代码吗?谢谢。

final AlertDialog d = new AlertDialog.Builder(this)
.setPositiveButton(android.R.string.ok, null)
.setIcon(R.drawable.icon)
.setMessage(Html.fromHtml("<a href=\"http://www.google.com\">Check this link out</a>"))
.create();
 d.show();
// Make the textview clickable. Must be called after show()   
         ((TextView)d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());

我想要的是:当用户打开我的应用程序时,我的警报框会显示一个链接,但我想使用许多链接并随机显示它们,我会将它用于类似文字广告。我的意思是当用户打开我的应用程序 google.com 时,将显示另一次 yahoo.com 和另一次不同的链接。希望我清楚

【问题讨论】:

    标签: android random hyperlink android-alertdialog


    【解决方案1】:

    你可以用这个:

    public static void showAlertDialog(final String title, String message,
                final Context context, final boolean redirectToPreviousScreen) {
            AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
            alertbox.setMessage(message);
            alertbox.setTitle(title);
    
            alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
    
                }
            });
            try{
                alertbox.show();    
            }catch (Exception b) {
    
            }
    
        }
    

    【讨论】:

    • 那么我应该把我的链接放在哪里随机显示?例如,google.com、yahoo.com
    • 当然把你的消息放在 setMessage() 方法中。但我没有得到你想要的。
    • 我想要的是:当用户打开我的应用程序时,我的警报框会显示一个链接,但我想使用许多链接并随机显示它们,我会将它用于类似文字广告。我的意思是当用户打开我的应用程序 google.com 时,将显示另一次 yahoo.com 和另一次不同的链接。希望我清楚
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2019-04-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多