对话框中的GraphView无法正常工作

问题描述 投票:0回答:1

当我在MainActivity.java中放置以下代码(同时在findViewById前面删除GraphDialog)时,它完美地运行。

但是当我将它放在我的对话框“GraphDialog”中时,logcat错误指向这一行(请参阅注释行)如果有人可以帮助我,那么感激不尽!谢谢!

    //Graph View function
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public void ShowGraphview(View v) {
    GraphView graphResult = GraphDialog.findViewById(R.id.graph);
    GraphDialog.setContentView(R.layout.ivb_popup_graphview);
    btn_close = GraphDialog.findViewById(R.id.dia_btn_close);
    GraphDialog.setCanceledOnTouchOutside(true);

    //Apply Graph view
    LineGraphSeries<DataPoint> series = new LineGraphSeries<>(new DataPoint[]{
            new DataPoint(0, 6),
            new DataPoint(1, 5),
            new DataPoint(2, 3),
            new DataPoint(3, 2),
            new DataPoint(4, 6)
    });

 //------------This line is where the logcat error pointed to-------
    graphResult.addSeries(series);
 //------------logcat error pointed to------------------------------

    /*Close Button */
    btn_close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            GraphDialog.dismiss();
        }
    });
    GraphDialog.show();
}
android-alertdialog android-graphview
1个回答
0
投票

当我交换这两行时工作....

GraphView graphResult = GraphDialog.findViewById(R.id.graph);

GraphDialog.setContentView(R.layout.ivb_popup_graphview);
© www.soinside.com 2019 - 2024. All rights reserved.