我正在构建一个使用Fragment和单个MainActivity的应用程序,它在同一个ViewPager中显示不同的片段,以复制典型MVC应用程序的行为.
问题是我还没有理解如何以编程方式更新片段以使用新的片段更改来更新ViewPager
例如,当我从main调用setFragment(int interval,Point [] snodePoint)时,我有这个片段显示图表(在我的意图中),图表应该在ViewPager中更新
public class LineFragment extends Fragment {
static int interval;
static Point snodePoints[];
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.fragment_linegraph, container,
false);
Bundle bundle = this.getArguments();
ChartConfig cg = bundle.getParcelable("FragmentData");
snodePoints = cg.getPoints();
interval= cg.getInterval();
Line l = new Line();
for(int i=0; i
LinePoint p = new LinePoint();
Point sp=snodePoints[i];
p.setX(sp.getX());
p.setY(sp.getY());
l.addPoint(p)
}
l.setColor(getResources().getColor(R.color.green));
LineGraph li = (LineGraph) v.findViewById(R.id.linegraph);
li.addLine(l);
li.setRangeY(0, interval);
li.setLineToFill(0);
li.setOnPoint