我有一个来自xml文件的自定义布局的alertdialog。为了使数字选择器工作,我必须为它们设置一些值。我该如何管理?
ShowMap类中的全局变量:
AlertDialog.Builder alert; //dialog f. koord.
static Dialog d ;
NumberPicker np1, np2, np3, np4, np5, np6, np7, np8;
String abc[] = new String[] { "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z" };
String zero_to_99[] = new String[100];
的ShowDialog():
public void showDialog()
{
final Context context=getApplicationContext();
//final Dialog d = new Dialog(ShowMap.this);
//Creating the AlertDialog object
final AlertDialog.Builder d = new AlertDialog.Builder(this);
//customDialog.setTitle("Custom Dialog");
LayoutInflater layoutInflater = (LayoutInflater)getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View view=layoutInflater.inflate(R.layout.dialog_pick_coord,null);
String txt_title = context.getResources().getString(R.string.txt_head_search_coord);
d.setTitle(txt_title);
np1 = (NumberPicker) findViewById(R.id.p1);
np2 = (NumberPicker) findViewById(R.id.p2);
np3 = (NumberPicker) findViewById(R.id.p3);
np4 = (NumberPicker) findViewById(R.id.p4);
np5 = (NumberPicker) findViewById(R.id.p5);
np6 = (NumberPicker) findViewById(R.id.p6);
np7 = (NumberPicker) findViewById(R.id.p7);
np8 = (NumberPicker) findViewById(R.id.p8);
//d.setContentView(R.layout.dialog_pick_coord);
d.setPositiveButton(context.getResources().getString(R.string.Accept), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Code to read out the pickers and work with the values
}
});
d.setNegativeButton(context.getResources().getString(R.string.Cancel), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
d.setView(view);
d.show();
}
setAlertDialogValues:
public void setAlertDialogValues() {
//Spalte
np1.setMaxValue(60); // max value 60
np1.setMinValue(1); // min value 1
np1.setWrapSelectorWheel(false);
//Zeile
np2.setMaxValue(25); // max value Z
np2.setMinValue(0); // min value A
np2.setDisplayedValues( abc );
np2.setWrapSelectorWheel(false);
//100km Quadrat 1
np3.setMaxValue(25); // max value Z
np3.setMinValue(0); // min value A
np3.setDisplayedValues( abc );
np3.setWrapSelectorWheel(false);
//100km Quadrat 2
np4.setMaxValue(25); // max value Z
np4.setMinValue(0); // min value A
np4.setDisplayedValues( abc );
np4.setWrapSelectorWheel(false);
//Easting xx*
np5.setMaxValue(99); // max value 99
np5.setMinValue(0); // min value 0
np5.setDisplayedValues( zero_to_99 );
np5.setWrapSelectorWheel(false);
//Easting **x
np6.setMaxValue(9); // max value 9
np6.setMinValue(0); // min value 0
np6.setWrapSelectorWheel(false);
//Northing xx*
np7.setMaxValue(99); // max value 99
np7.setMinValue(0); // min value 0
np7.setDisplayedValues( zero_to_99 );
np7.setWrapSelectorWheel(false);
//Northing **x
np8.setMaxValue(9); // max value 9
np8.setMinValue(0); // min value 0
np8.setWrapSelectorWheel(false);
np1.setValue(utmCoordElements[0]);
np2.setValue(utmCoordElements[1]);
np3.setValue(utmCoordElements[2]);
np4.setValue(utmCoordElements[3]);
np5.setValue(utmCoordElements[4]);
np6.setValue(utmCoordElements[5]);
np7.setValue(utmCoordElements[6]);
np8.setValue(utmCoordElements[7]);
}
我应该在哪里调用此功能?当我在d.show
之后调用它时,我收到了错误...
答案 0 :(得分:1)
变化:
np1 = (NumberPicker) findViewById(R.id.p1);
....
要:
np1 = (NumberPicker) view.findViewById(R.id.p1);
....