我想发送一条包含我的内容的阻止消息。我尝试了 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();
}
}