这是我的功能
public void populateList(View v){
ViewGroup LLview = (ViewGroup) v.findViewById(R.id.LinearLayout);
RelativeLayout row1 = new RelativeLayout(this);
LLview.addView();
}
View v = inflater.inflate(R.layout.fragment_lesson_list, container, false);
populateList(v);
第3行的'this'报错:RelativeLayout (android.context.Content) in relative layout cannot be applied to (ian.marxbrothers.LessonList)
我应该如何创建一个新的 RelativeLayout?我只想将它添加到 LLview
此方法位于 fragment 类 LessonList 中,该 fragment 类最终在 Adapter 之后被放入 MainMenu Activity。
感谢您的帮助,我已经尝试用谷歌搜索了好几个小时
最佳答案
public void populateList(View v){
ViewGroup LLview = (ViewGroup) v.findViewById(R.id.LinearLayout);
RelativeLayout row1 = new RelativeLayout(getActivity().getApplicationContext());
LLview.addView();
}
这通常适用于我或 getActivity().getBaseContext();
关于java - 如何将正确的上下文传递到新的 RelativeLayout 中?安卓java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30585955/