0

私のコンテンツを含むブロック メッセージを送信したいと思います。AlertDialog 機能を試してみました。問題は、メッセージ「さようなら」が「こんにちは」の前に表示されることです。私よりも簡単な解決策があるはずです。何か案は?

package com.example.a00;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
//import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {
    private static final int VISIBLE = 0;
    private static final int INVISIBLE = 4;
    private static final int GONE = 8;
    private String logval = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btnAlert = new Button(this);
        //btnAlert = (Button) findViewById(R.id.btnAlert);
        btnAlert.setOnClickListener(this);
        btnAlert.setVisibility(GONE);  // VISIBLE, INVISIBLE or GONE
        //
        logval = "hello";
        btnAlert.performClick();   // should be displayed first
        //
            // continue processing
            //
        logval = "good bye";        // should be displayed last 
        btnAlert.performClick();
    }

    public void onClick(View v) {
        AlertDialog alertDialog1 = new AlertDialog.Builder(
                MainActivity.this).create();
        alertDialog1.setTitle("Titre");
        //alertDialog1.setMessage("message");
        alertDialog1.setMessage(logval);
        alertDialog1.setButton("OK", new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(getApplicationContext(),
                        "Toast ...", Toast.LENGTH_SHORT).show();
            }
        });
        alertDialog1.show();
    }

}
4

1 に答える 1

0

hello最初のダイアログが開かれ、その上に開かれると思いますgood byedialog on the very top and then after it is closed, then the user sees theそのため、最終的には、最初に開かれた「Good Bye hello」ダイアログがユーザーに表示されます。

方法 1:

簡単なオプションの 1 つは、 の最初のダイアログを開くことですhello。次に、内部onClickで の別のダイアログを開きgood byeます。これが行うことは、ユーザーがok最初のダイアログで または他のボタンをクリックした場合にのみ、2番目のダイアログのみgood byeが開くということです。つまり、あるダイアログ ボックスonClickを別のダイアログ ボックスから開いてみてください。Android がダイアログから別のダイアログを表示し、のアラート ダイアログの後にアラート ダイアログを表示するのを参照してください。最初は行方不明!アンドロイド

方法 2:もう 1 つは、単純に両方の位置を逆にすることです。

logval = "good bye";
btnAlert.performClick();  
....
logval = "hello";
btnAlert.performClick();

そのため、Good bye最初に開きますが、すぐにそのhello上に開きます。お役に立てれば。

于 2013-08-18T09:14:20.793 に答える