2013-01-02 35 views
0

我使用AlertDialog显示任何消息和链接,我使用此代码。但我想随机地在每个动作中显示不同的消息(链接)。那可能吗?如果是的话,你可以给我这个样本代码。谢谢。如何在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()); 

我想要的是:当用户打开我的申请,我alertbox显示了一个链接,但我想用多少链接并显示它们随机的,我会用它像文字广告。我的意思是,当用户打开我的应用程序时,google.com将显示,另一次是yahoo.com,另一次是不同的链接。希望我清楚

回答

0

您可以使用此:

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) { 

     } 

    } 
+0

所以我应该在哪里把我的链接随机显示呢?例如,google.com,yahoo.com –

+0

当然,将您的消息放在setMessage()方法中。但我没有得到你想要的。 –

+0

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