Skip to content Skip to sidebar Skip to footer

Ondraw() For View

I just created one view in my layout file here:

Solution 1:

This is because you are creating the second instance of MyView. You need to make a reference to MyView which is in your layout:

MyView mv;  
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.main);

    mv = (MyView) findViewById(R.id.myview1);
    Button b1=(Button)findViewById(R.id.button1); 
    Button b2=(Button)findViewById(R.id.button2); 

    b1.setOnClickListener(new Button.OnClickListener(){ 

        public void onClick(View arg0) { 

            mv.setblue(); 

        } 

    }); 
    b2.setOnClickListener(new Button.OnClickListener(){ 

        public void onClick(View arg0) { 

            mv.setgreen(); 

        } 

    }); 
} 

Post a Comment for "Ondraw() For View"