[android-beginners] StringToFloat code

2010-06-19 Thread kille6525
Ok since the EditText.getText. will only allow you to get a string i
made a small program to get the string and convert it to a float. It
was a pain to do. You could change the return to an int or double but
i made this for floats...
Here is the horrible code...


 public float StringToFloat(String text)
 {
//Used for the for loops
 int i = 0;
//The number your go to return
 float number = 0;
//Used to specify if your before the decimal or after
 int numtodec = 1;
//Size of the int. 123.6 sizeofint = 3
 int sizeofint = -1;
//Gets the length of the String
 int size = text.length();
//Sets an array of characters equ to the string
 char string[] = text.toCharArray();
//Gets the size of the sizeofint and sizeofdec
 for(i = 0; i  size; ++i)
 {
 if(string[i] == '.')
 {
 numtodec = 0;
 continue;
 }
if(numtodec == 1)
++sizeofint;
 }
  //resets the num to dec
 numtodec = 1;
  //Stores the number
 for(i = 0; i  size; ++i)
 {
 if(string[i] == '.')
 {
 numtodec = 0;
 continue;
 }
int hold = string[i] - 48;
double hold2;
if(numtodec == 1)
hold2 = 
java.lang.Math.pow(10.0,(double)(sizeofint - i));
else
hold2 = 
java.lang.Math.pow(10.0,(double)(sizeofint+1 - i));
number += hold*hold2;
 }
 return number;
 }

-- 
You received this message because you are subscribed to the Google
Groups Android Beginners group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en


[android-beginners] Re: Need Help : canvas.drawtext() for a lengthy string

2010-01-17 Thread kille6525
Dont you have to wrap the text? like
android:layout_width=wrap_content

On Jan 7, 12:57 am, Latha Shivanna latha...@gmail.com wrote:
 Hi All

 I am stuck in a very simple problem.

 I have one lengthy string  I need to draw that on the device display.

 My code is as follows:

 void ShowText(String text) {
                  canv = thread.mSurfaceHolder.lockCanvas();    

                         if (text!= null) {

                                 canv.drawColor(Color.WHITE); //background 
 color
                                 mPaint.setColor(Color.BLACK); //font color
                                 mPaint.setTextSize(15);         //font size   
          
                                 canv.drawText(text, 10, 200, mPaint);         
                   //startign at some
 (10,200) coordinates , dratext
                         }

              unlockCanvasAndPost(canv);
         }

 But the problem here is, the string is going out of the screen. I want
 it to break down into multiple lines if it is too big for the screen
 width.

 Can anybody show me some example to do this?

 Thanks
 Latha
-- 
You received this message because you are subscribed to the Google
Groups Android Beginners group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en