[开发] 带输入框的AlertDialog问题

guying1028 2008-12-31
下面是我的代码:
public class Dialog2Text extends Activity {

private Button button;
private TextView view;
private EditText edit;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

button = (Button) findViewById(R.id.Button01);
view = (TextView) findViewById(R.id.TextView01);

final Builder builder = new AlertDialog.Builder(this).setIcon(
R.drawable.icon).setTitle("留点言吧").setMessage("谢谢留言").setPositiveButton("写完了",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
view.setText(edit.getText().toString());
}
});

button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
edit = new EditText(Dialog2Text.this);
builder.setView(edit);
builder.show();
}
});
}
}

Global site tag (gtag.js) - Google Analytics