Never mind - I figured it out! On Monday, 11 April 2016 11:11:50 UTC+1, Sharon Gilmore wrote: > > I'm creating an app in Android Studio, and I need to have one part of one > of the Activity screens which shows a grid. I'm having difficulty in > getting this set up, though. I've cut it back so that it should just > display some text in the appropriate area, but even that's not showing up. > I'm very new to Android Studio, and fairly new to Java, so am now stuck and > hoping someone can help. > > So far I have the following: > > Layout file (relevant section): > > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" > xmlns:custom="http://schemas.android.com/apk/res/com.example.packagename" > android:layout_width="match_parent" > android:layout_height="match_parent"> > <com.example.mypackagename.PatternGrid > android:layout_width="match_parent" > android:layout_height="match_parent" > android:id="@+id/patternGrid" /> > </LinearLayout> > > Attributes file: > <?xml version="1.0" encoding="utf-8"?> > <resources> > <declare-styleable name="PatternGrid"> > </declare-styleable> > </resources> > > > PatternGrid class: > > package com.example.mypackagename; > import... > > public class PatternGrid extends View { > > // Define paint and canvas > Paint gridPaint = new Paint(); > Bitmap gridBitmap; > Canvas gridCanvas; > > public PatternGrid(Context context, AttributeSet attrs) { > super(context, attrs); > gridPaint = new Paint(Paint.ANTI_ALIAS_FLAG); > gridPaint.setColor(Color.BLACK); > gridBitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); > gridCanvas = new Canvas(gridBitmap); > } > > protected void onDraw(Canvas canvas) { > super.onDraw(canvas); > // Draw the label text > canvas.drawText("Testing", 0, 0, 0, 0, gridPaint); > } > } > > And the relevant part of the Activity class: > > package **; > import ** > > > public class EditPattern extends AppCompatActivity { > > // Drawing grid > PatternGrid patternGrid; > > @Override > protected void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > > setContentView(R.layout.activity_edit_pattern); > > patternGrid = (PatternGrid) findViewById(R.id.patternGrid); > > } > > } > > When I run this, I don't see anything - just a blank screen. I can't see > anything in the error log that looks relevant. I'm guessing that I need to > call patternGrid.draw(), but when I do that it says I need to pass in the > Canvas variable. > > I tried declaring a canvas variable in the EditPattern class (which calls > the patternGrid class), which allowed me to call draw(), but it still > didn't show anything. > > Can anyone suggest what I'm doing wrong here? >
-- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/android-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/android-developers/602abfbf-f7f1-492c-bddb-26f79e3530ba%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

