EditText에서 사용자가 입력 한 결과를 별도의 대화 상자에 세부적인 방법으로 입력하려면 다음과 같이 입력하십시오. edittext. 어떤 도움을 주시면 감사하겠습니다.대화 상자에 편집 텍스트의 값을 입력하는 방법
EditText editText1,editText2,editText3;
Button btn,btn2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.btn);
btn2 = (Button) findViewById(R.id.btn2);
editText1 = (EditText) findViewById(R.id.editText2);
editText2 = (EditText) findViewById(R.id.editText3);
editText3 = (EditText) findViewById(R.id.editText4);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
calculate();
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
String s = " (Result) ";
alertDialogBuilder.setTitle("Detailed Output is");
alertDialogBuilder.setCancelable(false);
alertDialogBuilder.setMessage("(The code should be like as follows)\n\n"+"sum of entered number is:"+s+"\n"+"multiply of entered number is:"+s+"\n"+"subtraction of entered number is:"+s)
.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
});
}
public void calculate() {
String a = editText1.getText().toString();
String b = editText2.getText().toString();
editText3.setText(String.valueOf(Integer.parseInt(a)+ Integer.parseInt(b))+"\n"+String.valueOf(Integer.parseInt(a)* Integer.parseInt(b))+"\n"+String.valueOf(Integer.parseInt(a)-Integer.parseInt(b)));
}
}
당신은 당신의 문제가 무엇인지 잘 설명 할 수 있습니까? AlertDialog 메시지에서 editText1 및 editText2에 입력 된 두 숫자의 합계, 뺄셈 및 곱셈을 표시 하시겠습니까? –
@ValentinoS. 예 ..u 정확히 무슨 뜻인지 이해했습니다. – Rohan