public class Tab1 extends Fragment {
HorizontalBarChart barChart = (HorizontalBarChart)rootView.findViewById(R.id.barchartnew);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab1, container, false);
HorizontalBarChart barChart = (HorizontalBarChart)rootView.findViewById(R.id.barchartnew);
return rootView;
}
public void test(){
//Here I want to access barChart
}
在上面的代码中,我尝试从方法barChart
访问变量test()
。但是,当我尝试在public class Tab1 extends Fragment {
下方的顶部进行初始化时,我得到Cannot resolve symbol 'rootView'
我该如何解决这个问题?