gpt4 book ai didi

android - 是否可以膨胀 CustomLayout : FrameLayout in Xamarin in its own constructors and own class methods?

转载 作者:行者123 更新时间:2023-11-30 02:37:05 25 4
gpt4 key购买 nike

这是我想要膨胀的例子...它只是一个 FrameLayout 并且我有 Layout axml 文件...我可以从这个 FrameLayout 的父级(一个 fragment ) inflated layout ...我想要这个 Custom FrameLayout 在其他 fragment 中。在方法 initialize() 中,编译器说 Error CS1604: Cannot assign to '' because it is read-only (CS1604) (MyProject.Mono) 然后 Error CS0266: Cannot implicitly convert type 'Android.Widget.FrameLayout' to 'MyProject .Mono.ViewArtistAlbumTrack'。存在显式转换(是否缺少转换?)(CS0266) (Navi.Mono)

     /// <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()

}

最佳答案

我认为您的问题可能与此行有关:

 this = (FrameLayout)inflater.Inflate(Resource.Layout.ViewAAT, null);

这不是将布局加载到 View 中的正确方法。如果您的 View 是带有一些 subview 的自定义 FrameLayout,那么您可以将 xml 扩展到 FrameLayout 中并引用其中的 View ,例如

var frame = (FrameLayout)inflater.Inflate(Resource.Layout.ViewAAT, null);
this.trackdown = frame.FindViewById<Button>(...);
// find your other views here

关于android - 是否可以膨胀 CustomLayout : FrameLayout in Xamarin in its own constructors and own class methods?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26356214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com