tags:

views:

46

answers:

2

Say for example I have a textview in class A,
and I want to change background color of textview from class B through a method...
how can I do it?

+2  A: 

Make sure the tvView being passed is associated with a valid control (ie, findViewById() has been called before calling this function)

class B
{
public void changeBG(TextView tvView)
{
        tvView.setBackgroundColor(Color.BLUE);

}
};
st0le
Hey St0leits giving me java.lang.NullPointerExceptioni hv to do this "findViewById" in class A or class B?
shishir.bobby
`TextView tvTest = (TextView)findViewById(R.id.tv_id)` This should be in the `Activity` class. you can then pass this Variable Around and use it anywhere in any class.
st0le
+1  A: 

I think, you better have a public method changeBG in class A.
call that changeBG from Class B.

Vinay
actually, its working, but my textview is not visible after changing its background color..
shishir.bobby
I hope you have used the contrasting colors as background and foreground. so that the text is visible. :)
Vinay