0

メッセージとリンクを表示するために 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 が表示され、別の場合は別のリンクが表示されます。私がはっきりしていることを願っています

4

1 に答える 1

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

        }

    }
于 2013-01-02T11:58:18.957 に答える