在我的Android应用程序中,我将着色鸟素描。我需要用各种颜色给鸟的每一部分上色。我用这个位图的屏幕坐标来标识那些部分。现在我需要的是,当用户触摸身体部位的区域,然后打开另一个具有颜色列表的窗口。为此,我需要将我的View类的数据传递给新的Activity类。我怎样才能做到这一点?请给予帮助!将视图类中的数据传递给Android中的Activity类
我的视图类
class BirdColors extends View{
private Paint paint;
public Bitmap mBitmap,nBitmap;
public Canvas canvas;
private int x,y;
private CreateColorList colorList;
int val;
public BirdColors(Context context) {
super(context);
// TODO Auto-generated constructor stub
paint=new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
mBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.birdsketchfinal2).copy(Config.ARGB_8888, true);
mBitmap= Bitmap.createScaledBitmap(mBitmap, 230, 230, true);
//mBitmap=nBitmap;
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
this.canvas=canvas;
canvas.drawBitmap(mBitmap,0,0, null);
//canvas.drawText("Shashika", 10, 50, paint);
canvas.drawText("Screen Cordinates" +x+"x"+y, 10, 220, paint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
x=(int)event.getX();
y=(int)event.getY();
if((x>5 && x<23)&&(y>30 && y<47)){
val=1;
//colorList=new CreateColorList(val);
//In here I need to pass the val
}
invalidate();
}
return true;
}
我需要传递数据以专门识别用户在屏幕上触摸了哪个部分。 – Shashika
请粘贴代码已经完成 –
添加我的视图类 – Shashika