我有一个班级DFragment
。我将List<Map<String, String>>
传递给它的构造函数,我需要将传入的值存储在成员变量subVitalList
中。
我试过这样做:
this.subVitalList = subVitalList;
但是我在该行收到以下错误:
com.example.DFragment.this cannot be referenced from a static context
我不知道该怎么做。以下是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;
}
}
我做错了什么以及如何将传入的值正确存储在我的成员变量中?
答案 0 :(得分:3)
你可以试试这个,
片段类,
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;
}
}
您可以按如下方式传递列表:
DFragment dialog = new DFragment (mylist);