Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] java – How can ViewParent be cast into View?

Posted on November 11, 2022 By

Solution 1 :

This works in most cases because most ViewParents are ViewGroups.

ViewGroup extends View and implements ViewParent, so it satisfies both.

The reason that ViewParent is a separate interface is that this won’t always work: if you keep going up the tree, you’ll eventually find a ViewParent that is not a ViewGroup (specifically, you’ll get to the ViewRootImpl), and thus also not a View, and that will result in a ClassCastException.

Problem :

This code:

(View) contentView.getParent();

I don’t quite get it: ViewParent is an interface, View is a class that doesn’t implement that interface.

How do they transform into one another?

Comments

Comment posted by shadow_wxh

It’s also interesting that by accessing the inferface you actually accessing the the whole class that inplements the interface,I guess that is just the way it is.

Comment posted by Ryan M

Well, that’s what the cast is for: just accessing the interface along doesn’t get you the whole class. You have to be explicit that you know that it’s

READ  [FIXED] GestureDetector.OnGestureListener overridden methods for Android API 33 makes my application crash (Kotlin)
Powered by Inline Related Posts
Android Tags:android, android-view, java, view

Post navigation

Previous Post: [FIXED] java – Access Binding Adapters in multi module project
Next Post: [FIXED] java – Changing value in on item also changes in another item – RecyclerView Android

Related Posts

[FIXED] java – How to configure ble advertisement in android for ios to detect Android
[FIXED] android – viewpager instantiateItem() method’s error and not able to inflate layout in fragment Android
[FIXED] android – ionic backgroundFetch config not updating Android
[FIXED] android – How to add subtitle to your app in playstore? Android
[FIXED] android – How to create a video preview? Android
[FIXED] java – How to edit ionic cordova plugin Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme