gpt4 book ai didi

android - 在警报对话框中为数字选择器设置值

转载 作者:行者123 更新时间:2023-11-30 03:03:52 26 4
gpt4 key购买 nike

我有一个带有来自 xml 文件的自定义布局的警报对话框。为了让数字选择器工作,我必须为它们设置一些值。我该如何管理?

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];

显示对话框():

    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();
}

设置警报对话框值:

    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 之后调用它时出现错误...

最佳答案

改变:

 np1 = (NumberPicker) findViewById(R.id.p1);
....

收件人:

 np1 = (NumberPicker) view.findViewById(R.id.p1);
....

关于android - 在警报对话框中为数字选择器设置值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22134641/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com