Android: attempting to draw a canvas on a relative layout and eclipse wants to initialise a variable that shouldn't need it -
Hello EclipeE wants to get started:
CustomDrawableView mCustomDrawableView;
Any thoughts?
Cheers
Fill
Here is my code:
Package com.android.phil.graphtoggle; Import android App Import android.content.Context; Import Android.graphics. Canvas; Import android.graphics.drawable.ShapeDrawable; Import android.graphics.drawable.shapes.OvalShape; Importroid.os.Bundle; Import android.view.View; Import android.view.ViewGroup.LayoutParams; Import android.widget.ImageButton; Import android.widget.RelativeLayout; Public class broadens main activity activity {public int graph_toggle = 0; Public int data_tagle = 0; /** Called when the activity is first created. * / @Override Public Zero onCreate (bundled savedInstanceState) {super.onCreate (savedInstanceState); SetContentView (R.layout.main); Last Imejbtn Graf_tagle_btn = (Imejbtn) Pavarwubiaiaidi (Arkaijikgraf_togl); Final image button graph_stating_button = (image button) powerviewbid (rigprograph type); Last image button data_toggle_button = (image button) powerviewbid (rid.d_taggle); Custom Drawer View mCustomDrawableView; Relative layout main layout = find (relative layout) VVBIID (RID .relativeLayout1); RelativeLayout.LayoutParams LP = New Relative Layout. LayoutParam (layout parama.philant, 200); Lp.addRule (RelativeLayout.ALIGN_PARENT_BOTTOM); // Add another layout parameter rule to keep your custom button down; MCustomDrawableView.setLayoutParams (lp); MainLayout.addView (mCustomDrawableView); graph_toggle_button.setOnClickListener (New View.OnClickListener () {public void onClick (View arg0) {if (graph_toggle == 2) {graph_toggle = 0;} else {graph_toggle ++;} if (graph_toggle == 0) {graph_settings_button.setImageResource (R .drawable.close);} if (graph_toggle == 1) {graph_settings_button.setImageResource (R.drawable.ohlc_bars);} if (graph_toggle == 2) {graph_settings_button.setImageResource (R.drawable.candles);}} }); data_toggle_button.setOnClickListener (New View.OnClickListener () {public void onClick (View arg0) {if (data_toggle == 2) {data_toggle = 0;} {rest data_toggle ++;} if (data_toggle == 0) {data_toggle_button.setImageResource (R.drawable.ohlc_bars_daily);} if (data_toggle == 1) {data_toggle_button.setImageResource (R.drawable.ohlc_bars_weekly);} if (data_toggle == 2) {data_toggle_button.setImageResource (R.drawable.ohlc_bars_monthly);}} }); } Public Square CustomDrawableView Extends View {Removable Personal Imageography; Public CustomDrawableView (Reference Reference) {Super (Reference); Int x = 10; Int y = 100; Int width = 300; Intensity height = 50; MDrawable = New Size Drainage (New OvalSp ()); . MDrawable.getPaint () setColor (0xff74AC23); MDrawable.setBounds (X, Y, X + width, Y + height); } Safe vain on draw (canvas canvas) {mDrawable.draw (canvas); }}}
You can not start anywhere from mCustomDrawableView So the mCustomDrawableView.setLayoutParams (lp); is causing the cause of a NullPointerException . You are missing something like this
MCustomDrawableView = (CustomDrawableView) this.findViewById (R.id.my_custom_view);
Comments
Post a Comment