java - Android - How to start a new activity -
i'm trying make bull's eye random color, , instead of circles use squares.
but thing when run app on emulator , when starts new activity stops responding.
this main activity, 1 starts drawactivity.
public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); intent coiso = new intent(this, draw.class); startactivity(coiso); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } }
and draw activity, 1 want start. (it doesn't have things want do. because can't, problem ahead)
public class draw extends view { public draw(context context) { super(context); // todo auto-generated constructor stub } @override protected void ondraw(canvas canvas) { // todo auto-generated method stub super.ondraw(canvas); } }
can me? sorry english.
you have this
public class draw extends view
your class not extend activity
instead can below
draw draw = new draw(this); setcontentview(draw);
or have layout linear or relative , place add draw view layout after initializing.
setcontentview(r.layout.activity_main); linearlayout ll = (linearlayout)findviewbyid(r.id.linearlayout); // linear layout or relative layout in activity_main.xml. // place layout ahere want along other views draw draw = new draw(this); ll.addview(draw); // add customview linearlayout
edit:
remove this
intent coiso = new intent(this, draw.class); startactivity(coiso);
in activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > // customize linear layout needs. <linearlayout android:layout_width="200dp" android:layout_height="200dp" android:id="@+id/linearlayout" android:orientation="vertical" > </linearlayout> // other widgets </relativelayout>
in oncreate
setcontentview(r.layout.activity_main); linearlayout ll = (linearlayout)findviewbyid(r.id.linearlayout); draw draw = new draw(this); ll.addview(draw);
Comments
Post a Comment