Comments (6)
This looks like the line that is causing the InvalidCastException
:
__args [0] = new JniArgumentValue ((listener == null) ? IntPtr.Zero : ((global::Java.Lang.Object) listener).Handle);
My guess is your implementation of NavigationBarView.IOnItemSelectedListener
does not inherit from Java.Lang.Object
, which is required.
from androidx.
The following is a cut-down version that I’ve been using with X.A, Net7 and Net8. See any of the NavigationGraph examples at https://github.com/gmck for more details. I'm using Xamarin.Google.Android.Material 1.10.0.3.
I'm pretty sure it changed from the original implementation a couple of years back, but I now can't remember what the old way was.
NavigationBarView.IOnItemSelectedListener
bottomNavigationView!.ItemSelected += BottomNavigationView_ItemSelected!;
private void BottomNavigationView_ItemSelected(object sender, NavigationBarView.ItemSelectedEventArgs e)
{
…
... navController!.Navigate(e.Item.ItemId, null, navOptions);
}
from androidx.
Thank you for your helpful answers. From what I see, we weren't using the Java.Lang.Object which should be the issue. I will try this one and come back for feedback.
from androidx.
What do you get when you right-click NavigationView.IOnNavigationItemSelectedListener and then go to Definition
Mine has JavaObject.
public interface IOnNavigationItemSelectedListener : IJavaObject, IDisposable, IJavaPeerable
{
[Register("onNavigationItemSelected", "(Landroid/view/MenuItem;)Z", "GetOnNavigationItemSelected_Landroid_view_MenuItem_Handler:Google.Android.Material.Navigation.NavigationView/IOnNavigationItemSelectedListenerInvoker, Xamarin.Google.Android.Material")]
bool OnNavigationItemSelected(IMenuItem menuItem);
}
Does your main activity inherit from AppCompatActivity?
from androidx.
I had a bit of a brain fade last night when I posted the above. The above should have been about NavigationBarView.IOnItemSelectedListener, not NavigationView.
It should have read right-click on NavigationBarView.IOnItemSelectedListener
[Register("com/google/android/material/navigation/NavigationBarView$OnItemSelectedListener", "", "Google.Android.Material.Navigation.NavigationBarView/IOnItemSelectedListenerInvoker")]
public interface IOnItemSelectedListener : IJavaObject, IDisposable, IJavaPeerable
{
[Register("onNavigationItemSelected", "(Landroid/view/MenuItem;)Z", "GetOnNavigationItemSelected_Landroid_view_MenuItem_Handler:Google.Android.Material.Navigation.NavigationBarView/IOnItemSelectedListenerInvoker, Xamarin.Google.Android.Material")]
bool OnNavigationItemSelected(IMenuItem p0);
}
If you look at the IOnItemSelectedListenerInvoker below that, you'll see it inherits from Java.Lang.Object. If I remember correctly the change I referred to was introduced in Material 1.4.0
from androidx.
Thanks @gmck and @jpobst, both solutions worked. We ended using the ItemSelected event as it allows us to directly work on the handler without the need of a new class. I will close this issue.
from androidx.
Related Issues (20)
- Announcement: Xamarin.Android and .NET 6/7 no longer supported
- `Xamarin.Jetbrains.Annotations` namespace clash with `JetBrains.Annotations` causes CS0433 build failure HOT 1
- Can't install Xamarin.AndroidX.AppCompat and RecyclerView latest versions into Xamarin project HOT 2
- androidx.profileinstaller.ProfileInstaller.writeProfile java.lang.ClassNotFoundException: Didn't find class "com.google.common.util.concurrent.ListenableFuture" on path: DexPathList HOT 6
- Announcement: .NET 7 no longer supported HOT 1
- Bind AndroidX.ViewPager2 1.1.0 HOT 3
- error CS7069: Reference to type 'ILifecycleOwner' claims it is defined in 'Xamarin.AndroidX.Lifecycle.Common', but it could not be found HOT 1
- Still unable to use Xamarin.AndroidX.Emoji2.EmojiPicker
- Error running `api-diff` on `Xamarin.AndroidX.Car.App.App`
- after installation Xamarin.AndroidX.Work.Runtime 2.9.0.4 its giving error androidx.collection.ArrayMapKt on building the project in Visual Studio Community 2022 for Mac Version 17.6.9 HOT 2
- Recycler view (and other androidx controls) shows error in .xml preview HOT 2
- Media3 Exoplayer bug HOT 2
- Cannot replace a media item or seek in Exoplayer when adding a listener HOT 12
- Build issue with version 1.9.1 of `Xamarin.AndroidX.Activity` HOT 6
- Build error in LiveDataKt$observe$wrappedObserver$1.class HOT 9
- [AndroidX.Media3.Transformer] EditedMediaItem.Builder missing HOT 11
- Support for the new Watch Face Format HOT 2
- Bind "androidx.compose.ui" HOT 4
- [AndroidX.Media3.ExoPlayer] Removing MediaSourceFactory causes MediaSources not to inherit IMediaSourceFactory HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from androidx.