初始化变量时无法使用rootView

时间:2017-12-16 20:58:52

标签: java android mpandroidchart

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'

我该如何解决这个问题?

0 个答案:

没有答案