Java Interface type to c# binding

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Java Interface type to c# binding

venkatesh
Hi,

We have implemented the Pull to refresh and load more android library project into xamarin application.
In android java project , we have an  OnRefreshListener interface.

/**
         * Register a callback to be invoked when this list should be refreshed.
         *
         * @param onRefreshListener
         *            The callback to run.
         */
        public void setOnRefreshListener(OnRefreshListener onRefreshListener) {
                mOnRefreshListener = onRefreshListener;
        }

/**
         * Interface definition for a callback to be invoked when list should be
         * refreshed.
         */
        public interface OnRefreshListener {
                /**
                 * Called when the list should be refreshed.
                 * <p>
                 * A call to {@link PullToRefreshListView #onRefreshComplete()} is
                 * expected to indicate that the refresh has completed.
                 */
                public void onRefresh();

}

We need to call interface called OnRefreshListener on ListView in xamarin application project.
But we could not able to call OnRefreshListener in C# code.

Code snippets for java code to list view .

// Set a listener to be invoked when the list should be refreshed.
                ((PullAndLoadListView) getListView())
                                .setOnRefreshListener(new OnRefreshListener() {

                                        public void onRefresh() {
                                                // Do work to refresh the list here.
                                                new PullToRefreshDataTask().execute();
                                        }
                                });

But we need to call the above java code  to xamarin android in C#

Please suggest me on this.

Thanks




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Java Interface type to c# binding

venkatesh
This post was updated on .
Hi,

kindly give me some valuable suggestions on this issue.

//Java Class on List View

// Set a listener to be invoked when the list should be refreshed.
                ((PullAndLoadListView) getListView())
                                .setOnRefreshListener(new OnRefreshListener(){} )

//C# implementation on listview

public class ResfreshListener : Java.Lang.Object, PullToRefreshListView.IOnRefreshListener
        {
            public void OnRefresh()
            {
                Log.Info("PullToRefreshListViewDemo", "Test");
            }
        }

listview.setOnRefreshListener(new ResfreshListener () )

Error thrown  calling setOnRefreshListener on listview.

'Com.Costum.Android.Widget.PullAndLoadListView' does not contain a definition for 'SetOnRefreshListner' and no extension method 'SetOnRefreshListner' accepting a first argument of type 'Com.Costum.Android.Widget.PullAndLoadListView' could be found (are you missing a using directive or an assembly reference?)

Please guide me on this issue since  i am struggeld to solve this issue.

For your reference

api file  : api.xml

Generated c# file  : Com.Costum.Android.Widget.PullToRefreshListView.cs
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Java Interface type to c# binding

Jonathan Pryor-2
On Dec 5, 2013, at 12:42 AM, venkatesh <[hidden email]> wrote:
> 'Com.Costum.Android.Widget.PullAndLoadListView' does not contain a definition for '*SetOnRefreshListner*' and no extension method 'SetOnRefreshListner' accepting a first argument of type 'Com.Costum.Android.Widget.PullAndLoadListView' could be found (are you missing a using directive or an assembly reference?)
>
> api file  :  api.xml
> <http://mono-for-android.1047100.n5.nabble.com/file/n5713631/api.xml>  

Your api.xml does not declare any setOnRefreshListener() methods. In fact, there is only one method declared in api.xml that starts with "set": "setLastUpdated" (in PullToRefreshListView).

Please clean your project and provide diagnostic build output. In particular I'm after the `generator` warnings, to see why setOnRefreshListener() is being skipped.

        http://docs.xamarin.com/guides/android/deployment,_testing,_and_metrics/diagnostics/#Diagnostic_MSBuild_Output

Thanks,
- Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Java Interface type to c# binding

venkatesh
Hi,

Thanks for your prompt reply.
As you said , i have attached Diagnostic build output for binding project.

Diagnostic build output  :  DiagonosticBuild.txt

Kindly give me the valuable suggestion to solve the above issue.


Thanks

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Java Interface type to c# binding

Jonathan Pryor-2
On Dec 6, 2013, at 6:10 AM, venkatesh <[hidden email]> wrote:
> As you said , i have attached Diagnostic build output for binding project.

Here's the problem:

> 1>JARTOXML : warning J2XA005: missing class error was raised while reflecting setOnRefreshListener [public void com.costum.android.widget.PullToRefreshListView.setOnRefreshListener(com.costum.android.widget.PullToRefreshListView$OnRefreshListener)] : com/android/widget/R

Rephrased, our "jar2xml" program (what generates api.xml) wanted the com.android.widget.R type while processing the setOnRefreshListener() method, and the com.android.widget.R type doesn't exist (it's generated later).

I think this is a variation on: https://bugzilla.xamarin.com/show_bug.cgi?id=15885

Which isn't entirely gratifying...

You should be able to workaround this by editing Transforms\Metadata.xml, and adding the following (ugly) XML fragment:

        <add-node path="/api/package[@name='com.costum.android.widget']/class[@name='PullToRefreshListView']">
                <method name="setOnRefreshListener" return="void" abstract="false" native="false" synchronized="false" static="false" final="false" deprecated="not deprecated" visibility="public" >
                        <parameter name="listener" type="com.costum.android.widget.PullToRefreshListView.OnRefreshListener"/>
                </method>
        </add-node>

The above "manually" declares the setOnRefreshListener() method on the PullToRefreshListView type, and should allow the generator to bind the setOnRefreshListener() method.

Thanks,
- Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Java Interface type to c# binding

Ctls_Rajesh
Hi

Thanks for share with me....
Classteacher Learning Systems - Google Play Store | iTunes Play Store
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Java Interface type to c# binding

venkatesh
Hi,

Sorry for late mailing .
Thanks for your wonderful support. It's working now.


Thanks
Loading...