Android 4.2中的DropDown列表不起作用,在Android 2.2中运行良好

时间:2013-07-08 11:55:12

标签: android spinner android-2.2-froyo android-4.2-jelly-bean

我有一个在Android 2.2中运行良好的Spinner,但在Android 4.2中不起作用。

我尝试使用虚拟机进行调试,但是当我点击Spinner时,它在调试窗口中没有任何作用,虚拟机器人失去了焦点。

1 个答案:

答案 0 :(得分:1)

 Try This-


    Spinner spinnerQuantity;
        spinnerQuantity=(Spinner)findViewById(R.id.spinnerQuantity);
        ArrayAdapter<?> adapterQuantity = new ArrayAdapter<Object>(this, android.R.layout.simple_spinner_item,qtyArray);
                adapterQuantity.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                spinnerQuantity.setAdapter(adapterQuantity);

         spinnerQuantity.setOnItemSelectedListener(new OnItemSelectedListener() {

                    @Override
                    public void onItemSelected(AdapterView<?> parent, View v, int position,long id) {

                        pos=position;
                        System.out.println("selected position:"+pos);
                        if(pos!=0){
                            editItem.setVisibility(View.GONE);
                            spinnerQuantity.setVisibility(View.GONE);
                            textSelectQyt.setVisibility(View.GONE);
                        }
                        else{
                            editItem.setVisibility(View.VISIBLE);
                            spinnerQuantity.setVisibility(View.VISIBLE);
                            textSelectQyt.setVisibility(View.VISIBLE);
                        }
                    }

                    @Override
                    public void onNothingSelected(AdapterView<?> arg0) {
                        // TODO Auto-generated method stub
                        //do nothing
                    }
                });





     And in your xml-




 <Spinner
            android:id="@+id/spinnerQuantity"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/text_quantity"
            android:layout_below="@+id/text_quantity"
            android:layout_marginTop="0dp"
            android:prompt="@string/select_quantity" />

    It should work I have tested on all version..