textview.getLineCount始终为0的机器人 [英] textview.getLineCount always 0 in android
本文介绍了textview.getLineCount始终为0的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图动态调整我的TextView但getlinecount()方法总是返回我0,即使以后的setText()和无效()。我用下面的code:
I'm trying to dynamically resize my textview but getlinecount() method always returns me 0 even after settext() and invalidate(). I'm using the following code:
if(convertView == null){
convertView = lInflater.inflate(R.layout.listview, null);
holder = new ViewHolder();
holder.text2 = (TextView)convertView.findViewById(R.id.TextView02);
convertView.setTag(holder);
}
else{
holder = (ViewHolder)convertView.getTag();
}
holder.text2.setText(arr2[position]);
holder.text2.invalidate();
int lineCnt = holder.text2.getLineCount();
持有者是一个静态类,如下所示:
holder is a static class as follows:
static class ViewHolder{
TextView text2;
}
持有者中包含非空文本2和内容设置也非空。
holder contains non null text2 and the content set is also non null.
任何人都可以请帮助?
感谢名单提前。
推荐答案
我知道这个问题是很老,但万一有人来这里寻找实际的回答:
I know this question is quite old, but in case anyone comes here looking for the actual answer:
holder.text2.setText(arr2[position]);
holder.text2.post(new Runnable() {
@Override
public void run() {
int lineCnt = holder.text2.getLineCount();
// Perform any actions you want based on the line count here.
}
});
这篇关于textview.getLineCount始终为0的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文