Reputation: 2881
I have the following code in my activity. In my xml, the video view is inside the linear layout. However, when the view is clicked, the onTouchListener
never fires. I tried changing the onTouchListener
to vvLive
but that didn't do anything. I also tried changing the onTouchListener
to an onClickListener
, but nothing. Anyone know why the listener isn't firing? Thanks.
private VideoView vvLive;
LinearLayout linearLayoutLiveVideo;
linearLayoutLiveVideo.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event){
Log.d(TAG, "onTouch entered");
if(event.getAction() == MotionEvent.ACTION_UP) {
Log.d(TAG, "ACTION_UP");
}
return false;
}
});
EDIT:
I realized the code above actually works. Something in eclipse was messing up LogCat. After I restarted eclipse, LogCat prints the first log "onTouch entered". However, "ACTION_UP" was not being printed. I changed the MotionEvent to MotionEvent.ACTION_DOWN
and the LogCat prints now. Why does ACTION_DOWN
work but ACTION_UP
does not?
Upvotes: 16
Views: 34563
Reputation: 871
i have faces this issue and the solutions is:-
1-in your xml set the followin attribute to VideoView
android:clickable="true"
2- simply in your code set setOnClickListenerto the VideoView and it will work like charm:
videoView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(CinemaDetailsActivity.this , FullScreenPlayerActivity.class);
intent.putExtra("url" , getIntent().getStringExtra("url"));
startActivity(intent);
}
});
Upvotes: 1
Reputation: 54322
Modify your code like this and try:
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.d(TAG, "onTouch entered");
if(event.getAction() == MotionEvent.ACTION_UP) {
Log.d(TAG, "ACTION_UP");
return super.onTouchEvent(event);
else
return false;
}
Upvotes: 3
Reputation: 7220
ACTION_UP is never being sent to your listener because you return false and therefor don't "consume" the event. Return true and you'll get the start event (ACTION_DOWN) as well as all the subsequent ones (ACTION_MOVE and then ACTION_UP).
Upvotes: 37