views:

48

answers:

1

Hi all,

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;
} 

holder contains non null text2 and the content set is also non null.

Can anybody please help?

Thanx in advance.

A: 

getLineCount() will give you the correct number of lines only after a layout pass. That means the TextView must have been drawn at least once. I assume that at this point of time your Textview is not drawn hence you are getting 0 as the line count

Rahul
Thanx Rahul.. That's right, but I'm afraid wheather where to set this height if even not after setText().
neha
I am not sure where this code has been placed as of now. But if you have placed it under getview you text is shown/drawn only after you return the view object for that position
Rahul