2

I have a LinearLayout within a ScrollView in the xml file. I need to paint and write within the ScrollView so I've created a view in the layout and have been able to paint and write inside using: canvas.draw() and canvas.drawText(), my problem comes when writing text with canvas are not clearly the letters, so I need to add a TextView to the layout of the ScrollView from the class, without knowing very well how to do it. Paste the code:

public class Calendario extends Activity{
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.calendar);        
        LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
        MyView v = new MyView(this);
        layout.addView(v,250,2000);
     }

    private class MyView extends View{
        public MyView(Context context) {
            super(context);
        }
        protected void onDraw(Canvas canvas) {
            onDrawMethod();
            //Here draw and write text//
        }
     }
}

I need only add textviews inside A picture of what I need: I need only add textviews inside Thankss

1 Answers1

0

As I understand you, you want to add those texts programmaticaly, by saying

so I need to add a TextView to the layout of the ScrollView from the class

If so, might be this post will help you.

Community
  • 1
  • 1
Daler
  • 1,205
  • 3
  • 18
  • 39
  • Had already tried that, but in this line:"TextView valueTV = new TextView(this);" receipt NullPointerException –  May 25 '12 at 07:11
  • Do you set all propeties correcty when you create it. In the post below, it is all explained. If everything is fine and it still gives null exception, you might be need to clean your project. – Daler May 25 '12 at 07:16
  • I can create the TextView from the onCreate(), as in the post that you publish in the response, the problem is that I need to create it from my class MyView, that I need to create the textView dynamically because I need to add more without knowing the number of elements that I would like to add –  May 25 '12 at 07:24