1
我得到ClassCastException異常︰android.widget.LinearLayout 我試圖捕捉的事實,視圖(Lineralayout)具有listview(它的一個孩子)的元素,在裏面。Android轉換爲自定義ViewClassException:android.widget.LinearLayout
customview:
public class MasterView extends View {
public boolean done=false;
public MasterView(Context context) {
super(context);
}
public MasterView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MasterView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onFinishInflate() {
// TODO Auto-generated method stub
done=true;
super.onFinishInflate();
}
}
我叫它方式:
View master = (View)findViewById(R.id.master);
MasterView master2 = (MasterView)master; //exception
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/master"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/cnt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.03" >
</RelativeLayout>
</LinearLayout>
我膨脹CNT與列表中的XML
顯示XML代碼也.. – 2012-07-06 18:37:28
R.id.master是類型的LinearLayout不馬西德威 – 2012-07-06 18:58:54