如果用文本设置了android textview,是否有任何回调被调用
add a TextWatcher
to a TextView for watching text changes in TextView as:
TextView textView=(TextView)findViewById(R.id.txtview);
textView.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
//here you will get changed text in textview
}
});
另一种方法是:
if( TextView.getText().length() != 0) {}
You can simply check if your TextView has any text using the following:
TextView yourTextView = (TextView)findViewById(R.id.textViewID);
if(yourTextview.getText().toString().equals(""))
//it is blank
else
//it has text
我认为最好的方法是:
if(TextView.getText == null);
No. The only way to tell at runtime if user has set text from code is to create an instance
TextView tv = (TextView)findViewById(R.id.your_id)
and check if this text has text with getText()
method and see if your initially textView has text.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.