如何在ernestoyaquello垂直步进器中获取复选框值我无法使用视图

时间:2018-08-07 10:37:53

标签: android checkboxlist

我正在使用ernestoyaquello垂直步进器,并且在其中一个步骤中有多个复选框。

我想获取用户选中的所有复选框的值,但是我不能这样做,因为我无法使用视图解决此问题。

这是我实现复选框的方式:

private View SelectFilters(View view) {

    final CheckBox EngineFilter = new CheckBox(getContext());
    EngineFilter.setText(R.string.Engine_Filter);
    EngineFilter.setId(R.id.EngineFilter);
    CheckBox ACFilter = new CheckBox(getContext());
    ACFilter.setText(R.string.AC_Filter);
    ACFilter.setId(R.id.ACFilter);
    CheckBox FuelFilter = new CheckBox(getContext());
    FuelFilter.setText(R.string.Fuel_Filter);
    FuelFilter.setId(R.id.FuelFilter);
    CheckBox AirFilter = new CheckBox(getContext());
    AirFilter.setText(R.string.Air_Filter);
    AirFilter.setId(R.id.AirFilter);
    CheckBox OilFilter = new CheckBox(getContext());
    OilFilter.setText(R.string.Oil_Filter);
    OilFilter.setId(R.id.OilFilter);
    List<CheckBox> items = new ArrayList<CheckBox>();
    LinearLayout ll = new LinearLayout(getContext());
    LinearLayout llh = new LinearLayout(getContext());
    LinearLayout llh2 = new LinearLayout(getContext());
    ll.setOrientation(LinearLayout.VERTICAL);
    llh.setOrientation(LinearLayout.HORIZONTAL);
    ll.addView(llh);
    ll.addView(llh2);
    llh.addView(EngineFilter);
    llh.addView(OilFilter);
    llh.addView(ACFilter);
    llh2.addView(FuelFilter);
    llh2.addView(AirFilter);
    List<String> FiltersList = new ArrayList<>();
    boolean checked = ((CheckBox) view).isChecked();


    String filterList = "";

    // Check which checkbox was clicked
    switch (view.getId()) {
        case R.id.EngineFilter:
            if (checked) {
                filterList = EngineFilter.getText().toString();
                FiltersList.add(filterList);
            }
            // Remove the meat
            break;
        case R.id.FuelFilter:
            if (checked) {
                filterList = FuelFilter.getText().toString();
                FiltersList.add(filterList);
            }
            break;
        case R.id.ACFilter:
            if (checked) {
                filterList = ACFilter.getText().toString();
                FiltersList.add(filterList);
            }
            break;
        case R.id.AirFilter:
            if (checked) {
                filterList = AirFilter.getText().toString();
                FiltersList.add(filterList);
            }
            break;
        case R.id.OilFilter:
                if (checked) {
                    filterList = OilFilter.getText().toString();
                    FiltersList.add(filterList);
                }
                break;
    }
    // Cheese me 
    Toast.makeText(getContext(), FiltersList.get(0).toString(), Toast.LENGTH_LONG);
    return ll;
}

0 个答案:

没有答案