Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello my good friends,

When I try to set a drawableLeft in my android application like this:

TextView textView = new TextView() findViewById(R.id.mainList);
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.mul, 0, 0, 0);


I get a error with the first line:

"The constructer TextView() is undefined."
and
"The method findViewById(int) is undefined for the type Item."

How can I solve this? I am working in a class.

Thanks!

Stay sweet!

Update:

Basicly my question is: How can I access a TextView and set a drawableLeft (or for example text) in for example my Main Activity from a diffrent class?
Posted
Updated 4-Aug-11 4:39am
v2

1 solution

The doc:

TextView.setCompoundDrawablesWithIntrinsicBounds(int, int, int, int)[] @ developer.android.com/reference/android[^]

so your call of the method seems to be fine. Have you set a number value for the call R.drawable.mul ? That one might not be there when you request it.

You can also use a variable first and set that one into your code to check the value while debugging:
TextView textView = new TextView() findViewById(R.id.mainList);
int iLeft = R.drawable.mul;
textView.setCompoundDrawablesWithIntrinsicBounds(iLeft, 0, 0, 0);



Other idea: When is the view added to the app? is it already existing when you're trying to draw the bound? should you update the view (graphically)?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900