我有课,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;
}
}
我做错了什么以及如何正确地将传入的值存储在我的成员变量中?
最佳答案
你可以试试这个,
fragment 类,
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);
关于java - 将构造函数参数分配给成员变量, ".this cannot be referenced from a static context",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29484865/