选中复选框时,显示加载程序微调器

时间:2014-12-02 09:23:06

标签: android checkbox spinner

我有一个复选框,当选中它时,它会显示一个微调器,但我无法加载微调器包含的数据。

llF = (LinearLayout) view.findViewById(R.id.init_tour_foreign_producer_layout);
        llF.setVisibility(View.INVISIBLE);

        mySpinner = (Spinner)view.findViewById(R.id.spinner_init_tour);
        mySpinner.setAdapter(new ArrayAdapter<Tour>(this.getActivity(), android.R.layout.simple_spinner_item, s.getUnstartedTours()));

        /*---------- Managing the checkbox ----------*/
        cbAllProducer = (CheckBox) view
                .findViewById(R.id.enter_collection_check_other_tour);
        cbAllProducer
        .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                //checked = isChecked;
                if(isChecked){
                    llF.setVisibility(View.VISIBLE);
                    //mySpinner.setSelection(1);                    
                }
                else{
                    llF.setVisibility(View.GONE);
                }           
            }

        });     

2 个答案:

答案 0 :(得分:1)

获取selectedItem:

mySpinner.getSelectedItem();

获取某个位置的项目:

mySpinner.getAdapter().getItem(position);    

希望这对你有帮助!

答案 1 :(得分:0)

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    checkBox = (CheckBox) findViewById(R.id.chkbox);
    spinner = (Spinner) findViewById(R.id.spinner);
    List<String> list = new ArrayList<String>();

    list.add("Value1");
    list.add("Value2");
    list.add("Value3");
    list.add("Value4");

    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.sample_list, list);

    spinner.setAdapter(dataAdapter);

    spinner.setVisibility(View.INVISIBLE);
    checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            if (isChecked) {
                spinner.setVisibility(View.VISIBLE);
            } else {
                System.out.println("Not checked!!!!");
                spinner.setVisibility(View.INVISIBLE);
            }
        }
    });

}