java - Android View type at runtime -
i'm creating app used gridview display set of items. each of these items defined follows:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <com.example.myapp.customviews.tile android:layout_width="wrap_content" android:layout_weight="1" android:scaletype="fitcenter" android:layout_height="match_parent" android:id="@+id/tile" /> </linearlayout>
in onitemclickhandler
want check if type of view id r.id.tile
(my custom view class mentioned above) com.example.myapp.customviews.emptytile
. class child of tile class.
currently i'm checking if class emptytile follows:
linearlayout tilelayout = (linearlayout) gridview.getchildat(position); if (emptytile.class.isinstance(tilelayout.findviewbyid(r.id.tile))) { log.d("myappdebug", "correct instance!"); }
i have tried checking using instanceof
, tilelayout.findviewbyid(position).getclass() == emptytile.class
these don't work. @ runtime, view tile view , not emptytile view.
how can check if view instance of emptytile class?
instanceof must work. but, in xml, define view of type com.example.myapp.customviews.tile, why expect emptytile? if use emptytile (with correct package of course) in xml, instanceof check , other options work.
Comments
Post a Comment