How to determine the amount of characters that will fit into a TextView

by nwmotog...@gmail.com » Fri, 10 Apr 2009 06:11:55 GMT


Sponsored Links
 I am trying to place only the exact amount of data into a TextView but
I need to know how much it can hold.  Is there a way to do this based
on it's height, width and the textsize?
--~--~---------~--~----~------------~-------~--~----~



How to determine the amount of characters that will fit into a TextView

by nEx.Software » Fri, 10 Apr 2009 21:05:25 GMT


 I'd say if you know the text you want to put into the TextView, you
should be able to measure the text and compare to the size of the
TextView... In the API Demos, there is a measure text sample. I'd
start there.

On Apr 9, 3:11pm, "nwmotog...@gmail.com" <nwmotog...@gmail.com>


--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Subclass of ArrayAdapter not working

I have subclassed ArrayAdapter to set the color of text to RED if the
string does not contain 100%, this has been added to a ListView.  The
problem is that some of the rows show as red when they contain 100%.
Why would this happen?


        /*
         * Subclass of ArrayAdapter to change the color of the
         * text to red if it is not 100%
         *
         */
        public class ScoringAdapter extends ArrayAdapter<String> {

        private ArrayList<String> items;

        public ScoringAdapter(Context context, int textViewResourceId,
ArrayList<String> items) {
                super(context, textViewResourceId, items);
                this.items = items;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup
parent) {
                try {
                View v = convertView;
                if (v == null) {
                    LayoutInflater vi = (LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    v = vi.inflate
(android.R.layout.simple_list_item_1, null);
                }

                String item = items.get(position);
                TextView tv = (TextView) v.findViewById
(android.R.id.text1);
                tv.setText(item);

                if(!item.contains("100%")) {
                        tv.setTextColor(Color.RED);
                }

                return v;
                }
                catch(Exception e) {
                        e.printStackTrace();
                }

                return null;
        }
        }

-- 

2. Does Google think developers are lowest life form?

What purported to be a web company doesn't even let developers see
user comments from the so-called Developer Console.

Now they shut down Cryket.

What the fiick?

-- 

3. Google Wave

4. babbler vs bloo vs Facebook for androi

5. alive voice

6. Guru Meditation@ AudioTrack(51): *** SERIOUS WARNING *** obtainBuffer() timed out

7. Max size of android application