Friday 30 August 2013

Android: Get chars to fit in a textview width


int totalCharstoFit= textView.getPaint().breakText(fullString,  0, fullString.length(), 
 true, textView.getWidth(), null);
Now totalCharstoFit contains the exact characters that can be fit into one line. And now you can make a sub string of your full string and append it to the TextView like this,
String subString=fullString.substring(0,totalCharstoFit);
textView.append(substring);
And to calculate the remaining string, you can do this,
fullString=fullString.substring(subString.length(),fullString.length());
Now the full code,
Do this in a while loop,
while(fullstirng.length>0)
{
int totalCharstoFit= textView.getPaint().breakText(fullString,  0, fullString.length(), 
     true, textView.getWidth(), null);
 String subString=fullString.substring(0,totalCharstoFit);
    textView.append(substring);
 fullString=fullString.substring(subString.length(),fullString.length());

}

Android: How to detect device is Android phone or Android tablet?


public static boolean isTablet(Context context) {
    return (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK)
            >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

Friday 23 August 2013

android: Alert Dialog theme


AlertDialog action_btn = new AlertDialog.Builder(MyActivity.this, AlertDialog.THEME_TRADITIONAL).create();

Wednesday 21 August 2013

Android: Spacing between CheckBox and text


final float scale = this.getResources().getDisplayMetrics().density;
mRememberMyPwdCheckBox.setPadding(mRememberMyPwdCheckBox.getPaddingLeft() + (int)(10.0f * scale + 0.5f),
mRememberMyPwdCheckBox.getPaddingTop(),
mRememberMyPwdCheckBox.getPaddingRight(),
mRememberMyPwdCheckBox.getPaddingBottom());