The problem is that I put my code in the view class, the activity crashes because the button is "null". Here is a subset of my code:
Using java Syntax Highlighting
- @Override
- protected void onDraw(Canvas canvas) {
- // Clock-size rectangle to draw compliance windows
- RectF clockRect = new RectF(86, 6, 394, 314);
- // Create a node list containing each reminder
- NodeList reminderNodes = this.clockXML.getElementsByTagName("AdherenceInterval");
- int reminderLength = reminderNodes.getLength();
- Button checkbox = (Button) findViewById(R.id.checkbox);
- checkbox.setLayoutParams(new AbsoluteLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0, 0));
- checkbox.setOnClickListener(new Button.OnClickListener() {
- public void onClick(View v) {
- Context context = v.getContext();
- Intent i = new Intent(context, ReportMedications.class);
- context.startActivity(i);
- }
- });
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
I know this code works for creating buttons because I can put it in my activity class and it works just fine. Any suggestions? I thought about relocating the button in the activity, but I can't figure out how to do this when new data is available.



