0

I am trying to code a vertical stepper where in each step, I add a specific value to a hashmap that is declared outside all functions. When I try to retrieve the values added it is empty.

The below code shows some of the functions that am adding values to the hashmap in:

private View SelectFilters() {
    LayoutInflater inflater = LayoutInflater.from(getActivity().getBaseContext());
    LinearLayout selectfiltercontent = (LinearLayout) inflater.inflate(R.layout.select_filters_layout, null, false);

    CheckBox eng = (CheckBox)selectfiltercontent.findViewById(R.id.engfilter);
    CheckBox fue = (CheckBox)selectfiltercontent.findViewById(R.id.fuefilter);
    CheckBox oil = (CheckBox)selectfiltercontent.findViewById(R.id.oilfilter);
    CheckBox air = (CheckBox)selectfiltercontent.findViewById(R.id.airfitler);
    CheckBox ac = (CheckBox)selectfiltercontent.findViewById(R.id.acfilter);
    eng.setOnCheckedChangeListener(this);
    fue.setOnCheckedChangeListener(this);
    oil.setOnCheckedChangeListener(this);
    air.setOnCheckedChangeListener(this);
    ac.setOnCheckedChangeListener(this);

    return selectfiltercontent;
}

private View SelectOil() {
    RadioGroup rg = new RadioGroup(getContext());
    final RadioButton Shell5000 = new RadioButton(getActivity().getApplicationContext());
    Shell5000.setId(R.id.Shell5000KM);
    Shell5000.setText(R.string.Shell5000);

    final RadioButton Shell10000 = new RadioButton(getActivity().getApplicationContext());
    Shell10000.setId(R.id.Shell10000KM);
    Shell10000.setText(R.string.Shell10000);

    final RadioButton Mobil15000 = new RadioButton(getActivity().getApplicationContext());
    Mobil15000.setText(getString(R.string.Mobil1_5000));
    Mobil15000.setId(R.id.Mobil5000);
    final RadioButton Mobil110000 = new RadioButton(getActivity().getApplicationContext());
    Mobil110000.setText(R.string.Mobil1_10000);
    Mobil110000.setId(R.id.Mobil10000);
    final RadioButton ACDelco5000 = new RadioButton(getActivity().getApplicationContext());
    ACDelco5000.setText(R.string.ACDelco5000);
    ACDelco5000.setId(R.id.ACDelco5000);

    final RadioButton ACDelco10000 = new RadioButton(getActivity().getApplicationContext());
    ACDelco10000.setText(R.string.ACDelco10000);
    ACDelco10000.setId(R.id.ACDelco10000);
    rg.addView(Shell5000);
    rg.addView(Mobil15000);
    rg.addView(ACDelco5000);
    rg.addView(Shell10000);
    rg.addView(Mobil110000);
    rg.addView(ACDelco10000);
    rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch(checkedId){
                case R.id.Shell5000KM:
                    Data.put("OilType",Shell5000.getText().toString());
                    break;
                case R.id.Shell10000KM:
                    Data.put("OilType",Shell10000.getText().toString());
                    break;
                case R.id.Mobil5000:
                    Data.put("Oiltype",Mobil15000.getText().toString());
                    break;
                case R.id.Mobil10000:
                    Data.put("Oiltype",Mobil110000.getText().toString());
                    break;
                case R.id.ACDelco5000:
                    Data.put("OilType",ACDelco5000.getText().toString());
                    break;
                case R.id.ACDelco10000:
                    Data.put("OilType",ACDelco10000.getText().toString());
                    break;
                    default:
                        Data.put("OilType",getString(R.string.Empty));
            }
        }
    });
    return rg;
}

private View SelectTime() {
    TimePicker tp = new TimePicker(getContext());

    tp.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
        @Override
        public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
            String hout = String.valueOf(hourOfDay);
            String Minute = String.valueOf(minute);
            String TIME = hout+":"+Minute;
            Data.put("Time",TIME);
            Toast.makeText(getContext(),TIME,Toast.LENGTH_LONG).show();

        }
    });

This is where am trying to access them but fail

private View finalOrdered() {
    LayoutInflater inflater = LayoutInflater.from(getActivity().getBaseContext());
    RelativeLayout finalOrder =
            (RelativeLayout) inflater.inflate(R.layout.order_layout, null, false);
    TextView a = (TextView)finalOrder.findViewById(R.id.SelectedDate);
    a.setText(Order.getCarID());
    return finalOrder;
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Osama
  • 513
  • 2
  • 8
  • 18
  • Possible duplicate of [Android - Get value from HashMap](https://stackoverflow.com/questions/3422388/android-get-value-from-hashmap) – Abhinav Aug 14 '18 at 07:22
  • FYI, you are missing a '}' for function `SelectTime()`. Probably not the problem however. – Nic3500 Aug 14 '18 at 11:05
  • Your code seems to ignore standard identifier conventions: methods and variables should start with lowercase letters. This makes the code too hard to read. Sorry. – Stephen C Aug 15 '18 at 00:05

0 Answers0