-1
我有一個名爲CellView
的自定義視圖,它包含3 TextView
孩子。如果我在XML中創建新的佈局,並運行應用程序它工作正常。Android自定義查看孩子不可見
<com.example.views.CellView
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight="1"
custom:textTitle="My title text"
custom:textCenter="My center text"
custom:textFooter="My footer text" />
<com.example.views.CellView
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight="1"
custom:textTitle="My title text"
custom:textCenter="My center text"
custom:textFooter="My footer text" />
2個細胞在我的列表視圖中的每一行。
我有一個ArrayAdapter,如果它爲空並傳遞給我的列表視圖,我正在充氣convertView
。細胞是可見的,但孩子們不是!
CellView類包含getter和setter方法對每個對象(titleText,titleCenter,titleFooter),和我打電話getTitleText(),getCenterText()或getFooterText()當我在CellView
構造函數創建TextViews
。
public class CellView extends LinearLayout
{
// Objects and constructors... etc
public void setTitleText(String titleText)
{
this.titleText = titleText;
invalidate();
requestLayout();
}
}
ArrayAdapter 充氣觀點:
ViewHolder vh;
if (convertView == null)
{
convertView = (LinearLayout) inflater.inflate(R.layout.row_cells, null, false);
vh = new ViewHolder();
vh.cellLeft = (CellView) convertView.findViewById(R.id.left);
vh.cellRight = (CellView) convertView.findViewById(R.id.right);
convertView.setTag(vh);
}
vh = (ViewHolder) convertView.getTag();
vh.cellLeft.setTitleText(getItem(pos).getTextTitle());
vh.cellLeft.setCenterText(getItem(pos).getCenterText());
vh.cellLeft.setFooterText(getItem(pos).getFooterText());
// same for right cell
return convertView;
我覺得孩子文本視圖不重繪。每個修改對象的內容(標題,中心的文本或頁腳文本)調用自帶和呼籲invalidate()
requestLayout()