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?
views:
46answers:
2
+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
2010-08-12 04:48:14
Hey St0leits giving me java.lang.NullPointerExceptioni hv to do this "findViewById" in class A or class B?
shishir.bobby
2010-08-12 04:57:46
`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
2010-08-12 09:39:46
+1
A:
I think, you better have a public method changeBG in class A.
call that changeBG from Class B.
Vinay
2010-08-12 05:52:51
actually, its working, but my textview is not visible after changing its background color..
shishir.bobby
2010-08-12 06:30:03
I hope you have used the contrasting colors as background and foreground. so that the text is visible. :)
Vinay
2010-08-12 06:42:47