我有一个类drawView函数:如何在类扩展视图添加到现有类视图
public class DrawView extends View {
private ColorBall[] colorballs = new ColorBall[3]; // array that holds the balls
private int balID = 0; // variable to know what ball is being dragged
public DrawView(Context context) {
super(context);
setFocusable(true); //necessary for getting the touch events
// setting the start point for the balls
Point point1 = new Point();
point1.x = 50;
point1.y = 20;
Point point2 = new Point();
point2.x = 100;
point2.y = 20;
Point point3 = new Point();
point3.x = 150;
point3.y = 20;
// declare each ball with the ColorBall class
colorballs[0] = new ColorBall(context,R.drawable.bol_groen, point1);
colorballs[1] = new ColorBall(context,R.drawable.bol_rood, point2);
colorballs[2] = new ColorBall(context,R.drawable.bol_blauw, point3);
}
}
而且我现在的类是:
public class Quiz1 extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.e);
AbsoluteLayout l= (AbsoluteLayout)findViewById(R.id.ll);
DrawView d=new DrawView(this);
l.addView(d);
}
}
我想补充一点,drawView函数类,但其没有得到作为我的当前类视图的绝对布局的子视图添加没有任何错误执行,但我无法看到Drawview类对象。 ,当我这样做:
public class Quiz1 extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.e);
AbsoluteLayout l= (AbsoluteLayout)findViewById(R.id.ll);
DrawView d=new DrawView(this);
l.addView(d);
}
}
我得到的NullPointerException这意味着它不是renderring的drawView函数View.So底线是如何添加一个扩展来查看当前视图的类。 请帮助me..thanx
感谢名单Devunwired我想谈一下我的问题跟你说,如果我会做只的setContentView(新drawView函数(本)),那么我能够看到这种观点,我不能这样做在XML bcoz我drawView函数类正在处理复杂的图像拖放工作等。请帮助我。 –