我想创建在创建后点击屏幕的逻辑,我创建这样的东西:
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
MotionEvent newTouch = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN,
mSecondChart.getWidth() /2, mSecondChart.getHeight() /2, 0);
mSecondChart.dispatchTouchEvent(newTouch);
如您所见,我使用的是MpAndroidChart。我需要在创建图表后执行单击以生成一条线。但这没有用。
此外,我尝试点击处理程序。但也不行。
我怎么能这么好?
private void configureSecondAndThirdChart() {
ArrayList<CandleEntry> entries = new ArrayList<>();
entries.add(new CandleEntry(2, 5.25f, 3.02f, 3.50f, 4.50f));
CandleDataSet dataset = new CandleDataSet(entries, "# of Calls");
mSecondChart.getDescription().setEnabled(false);
mSecondChart.setBackgroundColor(Color.TRANSPARENT);
mSecondChart.getLegend().setEnabled(false);
YAxis leftAxis = mSecondChart.getAxisLeft();
leftAxis.setEnabled(false);
YAxis xAxis = mSecondChart.getAxisRight();
xAxis.setEnabled(false);
XAxis topAxis = mSecondChart.getXAxis();
topAxis.setEnabled(false);
dataset.setDecreasingColor(Color.TRANSPARENT);
dataset.setDecreasingPaintStyle(Paint.Style.STROKE);
dataset.setIncreasingColor(Color.TRANSPARENT);
dataset.setIncreasingPaintStyle(Paint.Style.STROKE);
dataset.setColor(Color.TRANSPARENT);
dataset.setShadowColor(Color.TRANSPARENT);
dataset.setNeutralColor(Color.TRANSPARENT);
dataset.setNeutralColor(Color.TRANSPARENT);
CandleData data = new CandleData(dataset);
mSecondChart.setData(data);
dataset.setColor(Color.RED);
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
MotionEvent newTouch = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN,
mSecondChart.getWidth() / 2, mSecondChart.getHeight() / 2, 0);
mSecondChart.dispatchTouchEvent(newTouch);
}
这是我在Fragment中的方法。我在OnCreatedView
中使用它