开发者

Android Java make bitmapfactory images clickable

Alright so how can I do this..

I have 2 classes

PlayActivity.java and Play.java

PlayActivity's setContentView is play.java

In play.java I have this:

gBall1 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
gBall2 = BitmapFactory.decodeResource(getResources(), R.drawable.womentrans);
gBall3 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
gBall4 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
gBall5 = BitmapFactory.decodeResource(getResources(), R.drawable.womentrans);
gBall6 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
gBall7 = BitmapFactory.decodeResource(getResources(), R.drawable.womentrans);
gBall8 = BitmapFactory.decodeResource(getResources(), R.drawable.womentrans);
gBall9 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
gBall10 = BitmapFactory.decodeResource(getResources(), R.drawable.womentrans);
gBall11 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
gBall12 = BitmapFact开发者_高级运维ory.decodeResource(getResources(), R.drawable.mantrans);
gBall13 = BitmapFactory.decodeResource(getResources(), R.drawable.womentrans);

And these appear on the screen..

How exactly can I make them clickable and show a toast?


You should set these bitmaps to an imageview and add a setOnClickListener to the imageview.

That way the images can be clicked on.


The basic premise here is that, in android, only a view is clickable. In your case the individual Bitmaps are contained is a View and therefore if a click listener can be applied to anything it has to be done on the View itself. i:e a bitmap cannot to made clickable unless it is put inside a view (ImageView in this case).

Therefore i suggest you make your Play class extend a Layout like FrameLayout or LinearLayout. Then add all the bitmaps to ImageViews and add the imageviews to the class.

 this.addView(childImageView)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜