我有一个带有 CalendarView 和 EditText 的布局,并在 AlertDialog 中显示它们,但是当我单击“确定”时,我无法获得 EditText (numberDecimal) 的值。
private void dialogHoras() {
LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout ll= (LinearLayout)inflater.inflate(R.layout.almanaque, null, false);
CalendarView cv = (CalendarView) ll.getChildAt(0);
final EditText input = (EditText)findViewById(R.id.etHoras);
cv.setFirstDayOfWeek(2);
cv.setOnDateChangeListener(new OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
dia = dayOfMonth; mes = month; anio = year;
}
});
new AlertDialog.Builder(this)
.setTitle("HORAS EXTRAS")
.setIcon(drawable.ic_launcher)
.setView(ll)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String res = input.getText().toString();
mensaje("INFO", "Se le deben... " + res + "horas");
}
}).setNegativeButton("Volver", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Do nothing.
}
} ).show();
}