simple code to find the Number of lines text exists in a TextView.Because we get the TextView Height in android

//using the Formula->"(eachLineHeight)*(n.Of lines in TextView)"..
        //before using below code u must set textView Width in .xml file as "android:lavout_width="200px"
        textView1=(TextView) findViewById(R.id.TextView1);
        textView1.setWidth(200);
        int charSize=200/8;
        System.out.println("------charSize--------"+charSize);
        String str=textView1.getText().toString();
        int count=0;
        int nbLines = 1;
        for(int i=0;i<str.length();i++)
        {
            count++;
            if(count>charSize)
            {
                count=0;
                nbLines++;
            }           
        }
        if(count>0)
            nbLines++;           
        System.out.println("************LineCount*****************"+nbLines);

Comments

Popular posts from this blog

Custom Dialog with no title and full screen in Android

code to display .pdf,.text,.DOC,.DOCX,.doc extension files exists in SDCard

Best working code to set Date limits on Date Picker Dialog,in Android