android中微调器项目选择的popwindow

android中微调器项目选择的popwindow,android,popup,Android,Popup,我有一个奇怪的问题。我正在使用微调器选择它的项目。我正在打开一个弹出窗口,但问题是,当第一次选择任何项目时,弹出窗口会打开,但如果再次选择该项目,则在再次选择该项目之前,只有选择任何其他项目,弹出窗口才会打开??我该怎么办??plss帮助下面是我的代码 @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

我有一个奇怪的问题。我正在使用微调器选择它的项目。我正在打开一个弹出窗口,但问题是,当第一次选择任何项目时,弹出窗口会打开,但如果再次选择该项目,则在再次选择该项目之前,只有选择任何其他项目,弹出窗口才会打开??我该怎么办??plss帮助下面是我的代码

      @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position,
            long id) {
        // TODO Auto-generated method stub
        switch (position) {
        case 0:

            break;
        case 1:
            pool_type_value=0;
            option_selected=2;
            calculation();
            break;

        case 2:
            pool_type_value=1;
            option_selected=2;
            System.out.println("pop up case 2");
            openPopupWindow(pool_legend);


            break;

        case 3:
            pool_type_value=2;
            option_selected=2;
            openPopupWindow(pool_legend);


            break;
        case 4:
            pool_type_value=0;
            option_selected=1;
            calculation();
            break;


        default:
            break;
        }

    }

          private void openPopupWindow(Spinner spinner) {
        // TODO Auto-generated method stub
        int h = 0;
        View popupView = null;
         Button btnDismiss = null;
        LayoutInflater layoutInflater 
         = (LayoutInflater)getBaseContext()
          .getSystemService(LAYOUT_INFLATER_SERVICE); 
         System.out.println("pop up ");
        if(width>240 && height>320)
          {
            h=350;

          }
        else if(width<=240 && height<=320){
            h=200;
        }
        if(pool_type_value==1){
         popupView = layoutInflater.inflate(R.layout.popup_rectangle_extension, null);
         btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
         ed_width_single_extension=(EditText)popupView.findViewById(R.id.editText_singleextension_width);
         ed_length_single_extension=(EditText)popupView.findViewById(R.id.editText_singleextension_lenght);

         System.out.println("pop up 1");
         if(!hashmap.get("single_width").equals("0")){
             ed_width_single_extension.setText(""+hashmap.get("single_width"));
             }
            if(!hashmap.get("single_length").equals("0")){
             ed_length_single_extension.setText(""+hashmap.get("single_length"));
             }

        }else if(pool_type_value==2){
         popupView = layoutInflater.inflate(R.layout.popup_rectangle_plus_extension, null);
         System.out.println("pop up 2");
         btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
        }
                 popupWindow = new PopupWindow(popupView, LayoutParams.FILL_PARENT,h);
                 popupWindow.setTouchable(true);
                 popupWindow.setFocusable(true);

                 btnDismiss.setOnClickListener(new Button.OnClickListener(){

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        hashmap.put("single_width", ed_width_single_extension.getText().toString());
                        hashmap.put("single_length", ed_length_single_extension.getText().toString());
                        calculation();

                        popupWindow.dismiss();
                        // setDatabase();
                    }



});



                popupWindow.showAtLocation( spinner, Gravity.CENTER, 0, 10);


    }
@覆盖
已选择公共位置(AdapterView父对象、视图、整型位置、,
长id){
//TODO自动生成的方法存根
开关(位置){
案例0:
打破
案例1:
池类型值=0;
所选选项_=2;
计算();
打破
案例2:
池类型值=1;
所选选项_=2;
System.out.println(“弹出框2”);
openPopupWindow(池_图例);
打破
案例3:
池_类型_值=2;
所选选项_=2;
openPopupWindow(池_图例);
打破
案例4:
池类型值=0;
选择的选项_=1;
计算();
打破
违约:
打破
}
}
私有void openPopupWindow(微调器微调器){
//TODO自动生成的方法存根
int h=0;
视图popupView=null;
按钮btnDismiss=null;
LayoutInflater LayoutInflater
=(LayoutFlater)getBaseContext()
.getSystemService(布局\充气机\服务);
System.out.println(“弹出”);
如果(宽度>240和高度>320)
{
h=350;
}
如果(宽度链接

表示当您再次单击当前选定的项目时,它无法触发任何事件。因此,您无法捕获setOnItemSelectedListener以供spinner响应。 摘自

试试这个

public class NoDefaultSpinner extends Spinner {

    private int lastSelected = 0;
    private static Method s_pSelectionChangedMethod = null;


    static {        
        try {
            Class noparams[] = {};
            Class targetClass = AdapterView.class;

            s_pSelectionChangedMethod = targetClass.getDeclaredMethod("selectionChanged", noparams);            
            if (s_pSelectionChangedMethod != null) {
                s_pSelectionChangedMethod.setAccessible(true);              
            }

        } catch( Exception e ) {
            Log.e("Custom spinner, reflection bug:", e.getMessage());
            throw new RuntimeException(e);
        }
    }

    public NoDefaultSpinner(Context context) {
        super(context);
    }

    public NoDefaultSpinner(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NoDefaultSpinner(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public void testReflectionForSelectionChanged() {
        try {
            Class noparams[] = {};          
            s_pSelectionChangedMethod.invoke(this, noparams);
        } catch (Exception e) {
            Log.e("Custom spinner, reflection bug: ", e.getMessage());
            e.printStackTrace();                
        }
    } 




    @Override
    public void onClick(DialogInterface dialog, int which) {    
        super.onClick(dialog, which);
            if(lastSelected == which)
                testReflectionForSelectionChanged();

            lastSelected = which;
    }
}

这是微调器的问题。如果选择了任何项目,再次单击同一项目,则不会调用itemSelectedListner。这就是您面临此问题的原因。thanxx…bt此问题的任何解决方案??微调器的设计方式使您无法重新选择相同的选定项目。对于助手,您可以通过编程方式选中此选项并设置选定的v当选择了一个值时,将值转换为其他值。至少我认为这应该有效。它会有效,但所选的值不会显示我选择的实际值。