【问题标题】:Show a loader spinner, when the checkbox is checked选中复选框时显示加载器微调器
【发布时间】:2014-12-02 17:59:08
【问题描述】:

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

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);
                }           
            }

        });     

【问题讨论】:

  • getUnstartedTours 是否返回任何东西?

标签: android checkbox spinner


【解决方案1】:

获取选中项:

mySpinner.getSelectedItem();

在某个位置获取项目:

mySpinner.getAdapter().getItem(position);    

希望对您有所帮助!

【讨论】:

    【解决方案2】:
    @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);
                }
            }
        });
    
    }
    

    【讨论】:

    • 它对我不起作用。这和我班上的一样
    猜你喜欢
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-19
    • 1970-01-01
    • 2013-04-10
    相关资源
    最近更新 更多