我修改后的工作示例基本上在下面我有 2 个编辑框我希望两者的值都显示在警报框中,其余代码工作正常,警报框确实显示但没有输入的值。
public class Main extends Activity {
EditText username = null;
EditText password = null;
Button login;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText usern = (EditText) findViewById(R.id.username);
EditText pass = (EditText) findViewById(R.id.password);
Button login = (Button) findViewById(R.id.login);
String usernm = usern.getText().toString();
String passnm = pass.getText().toString();
final Builder alert = new AlertDialog.Builder(this)
.setTitle("SHOW FIELDS")
.setMessage("USERNAME:" + usernm + " PASSWORD:" + passnm)
.setNegativeButton("CLOSE", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
closeContextMenu();
}
});
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alert.show();
}
});