i need draw some stuff on canvas and then lick on each. I made a class
public class PlayGameView extends SurfaceView implements SurfaceHolder.Callback
In this class I have onDraw method
@Override
public void onDraw(Canvas canvas) {
Paint paint = new Paint ();
Bitmap wrench = BitmapFactory.decodeResource(getResources(), R.drawable.wrench);
canvas.drawColor(Color .BLACK);
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
canvas.drawBitmap(wrench, canvas.getWidth()/2 - wrench.getWidth()*2 + i*wrench.getWidth(), 0 + j*wrench.getHeight(), null);
}
}
}
and inner class Thread.
so, in xml file i added this View like this
<com.cerbertek.PlayGameView
android:id="@+id/play_field_surface_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
and tying to add clicklistener in activity class
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.play_game);
playField = (PlayGameView) findViewById(R.id.play_field_surface_view);
playField.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(PlayGameActivity.this, "ОХУЕТЬ", 2000);
}
});
}
but nothing happens. no toast. when i called getWidth method it showed me ZERO! But I see the image)
how can i solve my problem?
You forgot to show it: