0

I have a class, DFragment. I'm passing a List<Map<String, String>> to its constructor, and I need to store the passed-in value in the member variable subVitalList.

I tried doing this:

this.subVitalList = subVitalList;

But I receive the following error on that line:

com.example.DFragment.this cannot be referenced from a static context

I'm not sure how to do this. Here is the code for DFragment:

public class DFragment extends DialogFragment {

    Context context;
    List<Map<String, String>> subVitalList;
    ListView vitalEntryListView;
    LayoutInflater mInflater;

    public static DFragment newInstance(List<Map<String, String>> subVitalList,int i) {
        DFragment f = new DFragment();
        // Supply num input as an argument.
        Bundle args = new Bundle();
        //args.putInt("num", num);
        args.putInt("num",i);

        //List<List<String>> svl = getArguments().getStringArrayList(subVitalList);
        return f;
    }

}

What am I doing wrong and how do I correctly store the passed-in value in my member variable?

Jason C
  • 38,729
  • 14
  • 126
  • 182
Drunken Daddy
  • 7,326
  • 14
  • 70
  • 104

1 Answers1

4

You can try this ,

Fragment class ,

public class DFragment extends DialogFragment {

    List<Map<String, String>> mylist;

    public DFragment () {   
        // Empty constructor required for DialogFragment
    }

    public DFragment (List<Map<String, String>> mylist) {
        this.mylist= mylist;
    }

}

You can pass the list as follows:

DFragment dialog = new DFragment (mylist);
Jason C
  • 38,729
  • 14
  • 126
  • 182
Heshan Sandeepa
  • 3,388
  • 2
  • 35
  • 45