Android 微调器弹出窗口错误
我正在做一个程序,当你给一个按钮,弹出窗口出现两个微调器,但我得到一个问题,当我试图初始化这些微调器。。。不知道为什么 我的弹出窗口:Android 微调器弹出窗口错误,android,spinner,popupwindow,Android,Spinner,Popupwindow,我正在做一个程序,当你给一个按钮,弹出窗口出现两个微调器,但我得到一个问题,当我试图初始化这些微调器。。。不知道为什么 我的弹出窗口: public void añadirRegistro(View v){ showPopup(leer_registros.this); } private void showPopup(final Activity context) { Spinner eleccionIP,eleccionRegistro; borra
public void añadirRegistro(View v){
showPopup(leer_registros.this);
}
private void showPopup(final Activity context) {
Spinner eleccionIP,eleccionRegistro;
borrar_datos BorrarDatos = new borrar_datos ();
// Inflate the popup_layout.xml
RelativeLayout viewGroup = (RelativeLayout) context.findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.popup_elegir_registros, viewGroup);
eleccionIP = (Spinner) layout.findViewById(R.id.popupIP);
eleccionRegistro = (Spinner)layout.findViewById(R.id.popupRegistro);
/*Cursor cur=BorrarDatos.obtenerIP();
BorrarDatos.rellenarSpinner(cur,eleccionIP);*/
final PopupWindow popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(LayoutParams.WRAP_CONTENT);
popup.setHeight(LayoutParams.WRAP_CONTENT);
popup.setFocusable(true);
popup.showAtLocation(layout, Gravity.NO_GRAVITY, 200, 200);
ArrayAdapter <CharSequence> adapter = new ArrayAdapter <CharSequence> (context, android.R.layout.simple_spinner_item );
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter.add("item 1");
adapter.add("item 2");
eleccionIP.setAdapter(adapter);
}
public void añadirRegistro(视图五){
showPopup(leer_registros.this);
}
私有void showPopup(最终活动上下文){
旋转器eleccionIP、eleccionRegistro;
borrar_datos BorrarDatos=新的borrar_datos();
//将弹出窗口_layout.xml充气
RelativeLayout视图组=(RelativeLayout)context.findViewById(R.id.popup);
LayoutInflater LayoutInflater=(LayoutInflater)context.getSystemService(context.LAYOUT\u INFLATER\u SERVICE);
视图布局=布局更平坦。充气(R.layout.popup\u elegir\u注册表,视图组);
eleccionIP=(微调器)layout.findviewbyd(R.id.popupIP);
eleccionRegistro=(微调器)layout.findviewbyd(R.id.popuregistro);
/*游标cur=BorrarDatos.obtenerIP();
BorrarDatos.rellenarSpinner(cur,eleccionIP)*/
最终弹出窗口=新弹出窗口(上下文);
popup.setContentView(布局);
popup.setWidth(LayoutParams.WRAP_内容);
popup.setHeight(LayoutParams.WRAP_内容);
popup.setFocusable(true);
弹出显示位置(布局,重力。无重力,200200);
ArrayAdapter=新的ArrayAdapter(上下文,android.R.layout.simple\u微调器\u项);
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
适配器。添加(“第1项”);
适配器。添加(“第2项”);
电源设置适配器(适配器);
}
我得到的错误是,按下微调器查看我一直在给我一个离开编译器的错误,而不是
当您给出一个按钮时,会出现一个带有两个微调器的弹出窗口
表示微调器位于弹出窗口内,因此请使用布局
实例将微调器初始化为:
......
View layout = layoutInflater.inflate(R.layout.popup_elegir_registros, viewGroup);
eleccionIP = (Spinner)layout.findViewById(R.id.popupIP);
eleccionRegistro = (Spinner)layout.findViewById(R.id.popupRegistro);
将此代码添加到微调器xml中
android:spinnerMode="dialog"
如果是那样的话,真的非常感谢你。现在我有了一个新问题,那就是如果我点击微调器查看其他有微调器的项目,我会出错,为什么?@Isma9:请更新您的最新代码和有问题的logcat结果,以获得我们的更多帮助