How does one access a particular widget from within a custom layout while using Alert Builder? As you can see below, I'm setting the alert to a widget that is created in the code, but I'd MUCH rather use predefined layout.
Current code:
private AlertDialog numberDialog(String title, final int dialogID){
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(title);
final NumberPicker np = new NumberPicker(this);
alert.setView(np);
alert.setPositiveButton(R.string.done, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
int newNumber = np.getCurrent();
calculatorVO.setWaiste(newNumber);
PFACalculator.this.updateList();
return;
}
});
alert.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
AlertDialog ad = alert.create();
return ad;
}
Psuedo-code for something I'd like:
private AlertDialog numberDialog(String title, final int dialogID){
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(title);
alert.setView(R.layout.numberDialog);
alert.setPositiveButton(R.string.done, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
NumberPicker np = (NumberPicker)findViewById(R.id.numpicker);
int newNumber = np.getCurrent();
calculatorVO.setWaiste(newNumber);
PFACalculator.this.updateList();
return;
}
});
alert.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
AlertDialog ad = alert.create();
return ad;
}
However, whenever I try to do it the second way I get a null pointer exception. Can anyone help?