对话框中的 GraphView 不工作 - logcat 中的错误
GraphView within a dialog not working - error in logcat
当我将以下代码(同时删除 findViewById 前面的 GraphDialog)放入我的 MainActivity.java 时,它运行良好。
但是当我把它放在我的对话框中时 "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();
}
当我交换这两行时有效....
GraphView graphResult = GraphDialog.findViewById(R.id.graph);
GraphDialog.setContentView(R.layout.ivb_popup_graphview);
当我将以下代码(同时删除 findViewById 前面的 GraphDialog)放入我的 MainActivity.java 时,它运行良好。
但是当我把它放在我的对话框中时 "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();
}
当我交换这两行时有效....
GraphView graphResult = GraphDialog.findViewById(R.id.graph);
GraphDialog.setContentView(R.layout.ivb_popup_graphview);