我正在开发一个 android 应用程序并使用 AChartEngine 来绘制图表。除了我在 OnTouch() 方法中捕获屏幕上的触摸坐标外,一切都正常工作。第一次触摸它不会返回任何坐标,并且 Toast 显示在左上角(由 Toast.setGravity() 设置)。在随后的触摸中,它工作得非常好,只是不是在我第一次点击或触摸屏幕时。我哪里错了?
mChartView.setOnClickListener(new View.OnClickListener() {
Toast test;
public void onClick(View v) {
SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
v.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
xaxis = event.getX();
yaxis = event.getY();
xx = (int) xaxis;
yy = (int) yaxis;
return false;
}
});
if (seriesSelection != null) {
int status_index = seriesSelection.getSeriesIndex();
int equipment_index = seriesSelection.getPointIndex();
double duration_value = seriesSelection.getValue();
if(status_index == 0)
{
if(equipment_index == 0)
{
duration_value = EquipmentHoursDuration[0][1];
}
if(equipment_index == 1)
{
duration_value = EquipmentHoursDuration[1][1];
}
if(equipment_index == 2)
{
duration_value = EquipmentHoursDuration[2][1];
}
if(equipment_index == 3)
{
duration_value = EquipmentHoursDuration[3][1];
}
if(equipment_index == 4)
{
duration_value = EquipmentHoursDuration[4][1];
}
String final_status = titles[status_index];
String final_equipment = EquipmentNamePartial[equipment_index];
test = Toast.makeText(
SalesBar.this,
"Status: " + final_status + '\n'
+ " Equipment: " + final_equipment + '\n'
+ " Duration: " + duration_value + " hours", Toast.LENGTH_SHORT);
test.setGravity(Gravity.TOP|Gravity.LEFT, xx, yy);
test.show();
}
else
{
String final_status = titles[status_index];
String final_equipment = EquipmentNamePartial[equipment_index];
if(equipment_index == 0)
{
duration_value = EquipmentHoursDuration[0][0];
}
if(equipment_index == 1)
{
duration_value = EquipmentHoursDuration[1][0];
}
if(equipment_index == 2)
{
duration_value = EquipmentHoursDuration[2][0];
}
if(equipment_index == 3)
{
duration_value = EquipmentHoursDuration[3][0];
}
if(equipment_index == 4)
{
duration_value = EquipmentHoursDuration[4][0];
}
test = Toast.makeText(
SalesBar.this,
"Status: " + final_status + '\n'
+ " Equipment: " + final_equipment + '\n'
+ " Duration: " + duration_value + " hours", Toast.LENGTH_SHORT);
test.setGravity(Gravity.TOP|Gravity.LEFT, xx, yy);
test.show();
}
}
}
});