我想通过Fragment中的“view.addContentView(dCircle,lParams)”绘制一些图片,但是它有一些问题。 AndroidStudio说变量“view”是从类中访问的,需要声明为final。
我该如何解决?
我的代码
public class FragmentHome extends BaseFragment {
public static final String FRAGMENT_TAG = "fragment";
private SelfCheck_Draw_Circle dCircle;
public static List<SelfCheck_Draw_Circle> saveCircle;
……
……
LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 700);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
context = getActivity().getApplicationContext();
initImageLoader(context);
View view = inflater.inflate(R.layout.selfcheck_main_tab, container, false);
……
……
draw_btn = (Button)view.findViewById(R.id.buttonadd);
draw_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
saveCircle = new ArrayList<>();
dCircle = new SelfCheck_Draw_Circle(**getApplicationContext()**);
**view.addContentView**(dCircle, lParams);
saveCircle.add(dCircle);
}
});
……
……
});
return view;
}
……
……