0

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

我尝试使用虚拟 android 进行调试,但是当我单击 Spinner 时,它在调试窗口中什么也不做,并且虚拟 android 失去焦点。

4

1 回答 1

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..
于 2013-07-08T12:21:10.693 回答