In C#, I need to write a constructor of a class as below which extends base class from android Library i.e. "Parcelable". I am getting an Error "Parcelable" does not contain a constructor that takes 0 arguments.
I saw C# Error: Parent does not contain a constructor that takes 0 arguments and Parent does not contain a constructor that takes 0 arguments but it did not work. My Class is as follows :
...
using Parcel = Android.OS.Parcel;
using Parcelable = Android.OS.Parcelable;
/// <summary>
/// Created by hashmi on 07/07/2015.
/// </summary>
public class Classname: Parcelable
{
private int id;
private string name;
private string address;
private string latitude;
private string longitude;
public Classname(int id, string name, string address, string latitude, string longitude)
{
this.id = id;
this.name = name;
this.address = address;
this.latitude = latitude;
this.longitude = longitude;
}
...
}
Code for the base class Parcelable is as follows:
using System;
using Android.Runtime;
using Java.Lang;
namespace Android.OS
{
[Register("android/os/Parcelable", ApiSince = 1, DoNotGenerateAcw = true)]
public abstract class Parcelable : Java.Lang.Object
{
[Register("CONTENTS_FILE_DESCRIPTOR")]
public const int ContentsFileDescriptor = 1;
[Obsolete("This constant will be removed in the future version. Use Android.OS.ParcelableWriteFlags enum directly instead of this field.")]
[Register("PARCELABLE_WRITE_RETURN_VALUE")]
public const ParcelableWriteFlags ParcelableWriteReturnValue = ParcelableWriteFlags.ReturnValue;
}
}
The base class is an Android Library abstract Class. I want to write a Constructor like "Classname" above without modifying the abstract base class that is "Parcelable".
I have edited the original code with the following code.
using Parcel = Android.OS.Parcel;
using Parcelable = Android.OS.Parcelable;
/// <summary>
/// Created by hashmi on 07/07/2015.
/// </summary>
public class LocationDetail : Parcelable
{
private int id;
private string name;
private string address;
private string latitude;
private string longitude;
public LocationDetail(int id, string name, string address, string latitude, string longitude)
: base(id, name, address, latitude, longitude)
{
this.id = id;
this.name = name;
this.address = address;
this.latitude = latitude;
this.longitude = longitude;
}
...
}
The new error is "Parcelable" does not contain a constructor that takes 5 arguments