对话框中的GraphView不起作用

时间:2018-08-26 15:26:47

标签: android-alertdialog android-graphview

当我在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();
}

1 个答案:

答案 0 :(得分:0)

当我交换这两行时有效。...

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

GraphDialog.setContentView(R.layout.ivb_popup_graphview);