I\'ve got a custom view and I want to get the X and Y coordinates of a user click. I\'ve found that I can only get the coordinates from the onTouchEvent and an onClickEvent
I have able solve this problem
I created an Custom View public class QuestionBuilderView extends View
In layout File
< com.example.android.view.QuestionBuilderView
android:id="@+id/questionbuilderview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
In an main Activity try to call the custom view and set the Onclick / On Touch Event Listener to the view
View questionBuilder = findViewById(R.id.questionbuilderview);
questionBuilder.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
// TODO Auto-generated method stub
float touched_x = event.getX();
float touched_y = event.getY();
Toast.makeText(getApplicationContext(), " "+touched_x +","+touched_y, Toast.LENGTH_LONG).show();
// int action = event.getAction();
return true;
}