public class ViewUtils
extends java.lang.Object
TextView textView = ViewUtils.findViewById
(this, R.id.my_text_view);
//no more casting!TextView textView = ViewUtils.findViewById
(parentView, R.id.my_text_view);
//no more casting!String text = ViewUtils.getText
(this, R.id.my_text_view);
ViewUtils.setText
(this, R.id.my_text_vew, "new text");
ViewUtils.setText
(textView, "new text");
ViewUtils.appendText
(textView, "appended");
ViewUtils.hideView
(this, R.id.my_text_view);
ViewUtils.showView
(this, R.id.my_text_view);
Bitmap bitmap = ViewUtils.viewToImage
(this, R.id.my_layout);
ViewUtils.showKeyboard
(this, R.id.my_text_view);
ViewUtils.closeKeyboard
(this, R.id.my_text_view);
Constructor and Description |
---|
ViewUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
appendText(android.widget.TextView view,
java.lang.String toAppend)
Append given text String to the provided view (one of TextView or EditText).
|
static void |
closeKeyboard(android.content.Context context,
android.view.View field)
Go away keyboard, nobody likes you.
|
static <T extends android.view.View> |
findViewById(android.app.Activity context,
int id)
Utility method to make getting a View via findViewById() more safe & simple.
|
static <T extends android.view.View> |
findViewById(android.view.View parentView,
int id)
Utility method to make getting a View via findViewById() more safe & simple.
|
static java.lang.String |
getText(android.app.Activity context,
int id)
Get text as String from EditView.
|
static java.lang.String |
getText(android.widget.TextView view)
Get text as String from EditView.
|
static void |
hideView(android.app.Activity context,
int id)
Sets visibility of the given view to
View.GONE . |
static void |
setText(android.app.Activity context,
int field,
java.lang.String text)
Method used to set text for a TextView
|
static void |
setText(android.view.View parentView,
int field,
java.lang.String text)
Method used to set text for a TextView
|
static void |
showKeyboard(android.content.Context context,
android.view.View field)
Show the pop-up keyboard
|
static void |
showView(android.app.Activity context,
int id)
Sets visibility of the given view to
View.VISIBLE . |
static android.graphics.Bitmap |
viewToImage(android.content.Context context,
android.webkit.WebView viewToBeConverted)
Convert view to an image.
|
public static <T extends android.view.View> T findViewById(android.app.Activity context, int id)
context
- The current Context or Activity that this method is called fromid
- R.id value for viewjava.lang.ClassCastException
- if cast to the expected type breaks.public static <T extends android.view.View> T findViewById(android.view.View parentView, int id)
parentView
- Parent View containing the view we are trying to getid
- R.id value for viewjava.lang.ClassCastException
- if cast to the expected type breaks.public static java.lang.String getText(android.widget.TextView view)
view
- EditView to get text frompublic static java.lang.String getText(android.app.Activity context, int id)
context
- The current Context or Activity that this method is called fromid
- Id for the TextView/EditView to get text frompublic static void appendText(android.widget.TextView view, java.lang.String toAppend)
view
- View to updatetoAppend
- String textpublic static void closeKeyboard(android.content.Context context, android.view.View field)
context
- The current Context or Activity that this method is called fromfield
- field that holds the keyboard focuspublic static void showKeyboard(android.content.Context context, android.view.View field)
context
- Activity/Contextfield
- field that requests focuspublic static android.graphics.Bitmap viewToImage(android.content.Context context, android.webkit.WebView viewToBeConverted)
context
- The current Context or Activity that this method is called fromviewToBeConverted
- View to convert to a Bitmappublic static void setText(android.app.Activity context, int field, java.lang.String text)
context
- The current Context or Activity that this method is called fromfield
- R.id.xxxx value for the text field.text
- Text to place in the text field.public static void setText(android.view.View parentView, int field, java.lang.String text)
parentView
- The View used to call findViewId() onfield
- R.id.xxxx value for the text field.text
- Text to place in the text field.public static void hideView(android.app.Activity context, int id)
View.GONE
.context
- The current Context or Activity that this method is called fromid
- R.id.xxxx value for the view to hide"expected textView to throw a ClassCastException" + textViewpublic static void showView(android.app.Activity context, int id)
View.VISIBLE
.context
- The current Context or Activity that this method is called fromid
- R.id.xxxx value for the view to show