Reputation: 61
I want to check dynamically if textView is full or not with given text. i.e. In a TextView I assign Text dynamically. and also I want to check whether that TextView is full of text with given text or not. and that textview lies in custom listview. my textview is having max line 3.
Upvotes: 2
Views: 848
Reputation: 1664
you need to calculate the size of your textview and the size of your text. Try this to find size of your text view
int text_view_size = text_view.getLayoutParams().width;
and this for finding the size of your text
int text_size = getTextSize(text_view.getText().toString());
this is getTextSize method
private int getTextSize(String your_text){
Paint p = new Paint();
//Calculate the text size in pixel
return p.measureText(your_text);
}
Now you can check using text watTextWatcher class that your text exceeds the size of your text view.
Upvotes: 4
Reputation: 6728
try this
if(textView.getText().toString().trim().length()<=0)
{
//here your textview has no text
}
Upvotes: -1
Reputation: 10100
Use TextWatcher to see when the text has changed :
private TextView mTextView;
private EditText mEditText;
private final TextWatcher mTextEditorWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
//This sets a textview to the current length
mTextView.setText(String.valueOf(s.length()));
}
public void afterTextChanged(Editable s) {
}};
Also check this :TextWatcher example
Upvotes: 0