我在片段中创建了一个视图
public static class GraphSectionFragment extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
GraphView view = new GraphView(getActivity());
view.setGraphType(GraphView.GraphType.Oscillator);
return view;
}
}
现在我需要从主要活动中访问我的 GraphView 对象。我如何能?我以这种方式尝试过,但它不起作用。
GraphSectionFragment fr = (GraphSectionFragment) m_SectionsPagerAdapter.getItem(0);
View v = fr.getView();
GraphView graph = (GraphView)v;
graph.setData(0, m_DeviceThread.getRangeDataI());
m_SectionsPagerAdapter 是从 FragmentPagerAdapter 继承的类的对象。Fragment.getView 返回一些奇怪类的视图,而不是 GraphView。