Reputation: 863
I was following an example for OnTouchListner in android application . I had written the following code . I am implemneting an activity for ontouchlistner and the creating a toast for action move, up and down but its not showing anything...
here is the activity code:
public class GameActivity extends Activity
implements OnTouchListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Intent intent = getIntent();
setContentView(R.layout.layout_game);
//create grid view
splitImage();
GridView gridView = new GridView(this);
gridView = (GridView)findViewById(R.id.grid_view);
final ImageAdapter images = new ImageAdapter(this,chunkedImages);
final GridView gV = gridView;
gridView.setAdapter(images);
}
....
public boolean onTouch(View v, MotionEvent me) {
switch(me.getAction())
{
case MotionEvent.ACTION_DOWN :
Toast.makeText(GameActivity.this, "down" , Toast.LENGTH_SHORT).show();
break;
case MotionEvent.ACTION_UP :
Toast.makeText(GameActivity.this, "up", Toast.LENGTH_SHORT).show();
break;
case MotionEvent.ACTION_MOVE :
Toast.makeText(GameActivity.this, "move", Toast.LENGTH_SHORT).show();
break;
}
return true;
}
}
Upvotes: 0
Views: 322
Reputation: 82543
You also need to set your listener to something. Right now, it's capable of receiving touch events, but it won't.
Add the following line to your onCreate():
gridView.setOnTouchListener(this);
Upvotes: 3