다음은 내가 팽창시키고 싶은 예제입니다. 그냥 FrameLayout이고 Layout axml 파일이 있습니다 ...이 FrameLayout (단편)의 부모로부터 레이아웃을 부 풀릴 수 있습니다 ... 이걸 원해요. 다른 조각의 사용자 정의 FrameLayout. 메서드 initialize()에서 컴파일러는 오류 CS1604 : 읽기 전용 (CS1604) (MyProject.Mono)이고 오류 CS0266 : 암시 적으로 'Android.Widget.FrameLayout'형식을 'MyProject .Mono.ViewArtistAlbumTrack '. 명시 적 변환이 존재한다 (당신은 캐스트를 누락?) (CS0266) (Navi.Mono)Xamarin에서 CustomLayout : FrameLayout을 자체 생성자로 확장하고 클래스 메서드를 소유 할 수 있습니까?
/// <summary>
/// View artist album track.
/// This framelayout is especific for ...
/// </summary>
public class ViewArtistAlbumTrack : FrameLayout
{
/// <summary>
/// The adapter.
/// </summary>
public ExpandableAATitemAdapter adapter = null;
/// <summary>
/// a plain ExpandableListView
/// </summary>
public ExpandableListView expandable = null;
/// <summary>
/// View that triggers something sliding up
/// </summary>
public Button albumdown = null;
public Button trackdown = null;
/// <summary>
/// The list just AAT items. AAT is for Artist Album Track
/// </summary>
public List<AATitem> list = null;
public ViewArtistAlbumTrack (Context context) :
base (context)
{
this.trackdown = new Button(this.Context);
this.albumdown = new Button(this.Context);
this.expandable = new ExpandableListView(this.Context);
Initialize();
}
public ViewArtistAlbumTrack (Context context, IAttributeSet attrs) :
base (context, attrs)
{
this.trackdown = new Button(this.Context);
this.albumdown = new Button(this.Context);
this.expandable = new ExpandableListView(this.Context);
Initialize();
}
public ViewArtistAlbumTrack (Context context, IAttributeSet attrs, int defStyle) :
base (context, attrs, defStyle)
{
Initialize();
}
public void Initialize()
{
try
{
LayoutInflater inflater = (LayoutInflater)this.Context.GetSystemService(Context.LayoutInflaterService);
this = (FrameLayout)inflater.Inflate(Resource.Layout.ViewAAT, null);
Console.WriteLine("done succesfully: "+ System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()+ " "
+ System.Reflection.MethodBase.GetCurrentMethod().Name.ToString());
}
catch(Exception exception)
{
Console.WriteLine ("exception at "
+ System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()+ " "
+ System.Reflection.MethodBase.GetCurrentMethod().Name.ToString() + " : "
+ exception.Source.ToString());
Console.WriteLine ("exception at "
+ System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()+ " "
+ System.Reflection.MethodBase.GetCurrentMethod().Name.ToString()+ " : "
+ exception.Message.ToString());
Console.WriteLine ("exception at "
+ System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()+ " "
+ System.Reflection.MethodBase.GetCurrentMethod().Name.ToString()+ " : "
+ exception.StackTrace.ToString());
Console.WriteLine ("exception at "
+ System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()+ " "
+ System.Reflection.MethodBase.GetCurrentMethod().Name.ToString()+ " : "
+ exception.TargetSite.ToString());
}// end of catch()
//this.expandable.SetAdapter(new ExpandableAATitemAdapter(Application.Context, this.list));
}
protected override void OnFinishInflate()
{
try
{
this.trackdown = new Button(this.Context);
this.albumdown = new Button(this.Context);
this.expandable = new ExpandableListView(this.Context);
this.expandable = FindViewById<ExpandableListView> (Resource.Id.aatexpandableid);
this.trackdown = FindViewById<Button> (Resource.Id.aattracksbid);
this.albumdown = FindViewById<Button> (Resource.Id.aatabumsbid);
this.trackdown.Visibility = ViewStates.Gone;
this.albumdown.Visibility = ViewStates.Gone;
Console.WriteLine("done succesfully: "+ System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()+ " "
+ System.Reflection.MethodBase.GetCurrentMethod().Name.ToString());
}
catch(Exception exception)
{
Console.WriteLine ("exception at "
+ System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()+ " "
+ System.Reflection.MethodBase.GetCurrentMethod().Name.ToString() + " : "
+ exception.Source.ToString());
Console.WriteLine ("exception at "
+ System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()+ " "
+ System.Reflection.MethodBase.GetCurrentMethod().Name.ToString()+ " : "
+ exception.Message.ToString());
Console.WriteLine ("exception at "
+ System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()+ " "
+ System.Reflection.MethodBase.GetCurrentMethod().Name.ToString()+ " : "
+ exception.StackTrace.ToString());
Console.WriteLine ("exception at "
+ System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()+ " "
+ System.Reflection.MethodBase.GetCurrentMethod().Name.ToString()+ " : "
+ exception.TargetSite.ToString());
}// end of catch()
}
}
XML에서 'FrameLayout' 또는 사용자 정의 유형으로 정의하고 있습니까? 내 axml에 – ScouseChris
을 사용자 정의 유형 (ViewArtistAlbumTrack)으로 저장 한 다음 나중에 ViewArtistAlbumTrack으로 캐스팅하려고하는 FrameLayout으로 사용합니다. – carlesls