For my custom view I have also defined a custom attribute for keep id of the view. Its format is "reference".
in layout xml it is defined like below, very similar with android:layout_below
attr
<mycustomview id="@+id/cv_1" xyz:nextviewId="@id/cv_2"... />
<mycustomview id="@+id/cv_2" xyz:nextviewId="@id/cv_3"... />
...
<LinearLayout ...>
<mycustomview id="@+id/cv_3" xyz:nextviewId="@id/cv_4"... />
</LinearLayout>
...
it gives me error I think it is because it is not declared yet.
Any suggestion for accessing the next object similar to this approach!!!
I am thinking to use tag attr for the next object find the next one with findByTag function. Is this a good way to do it.
A well-designed custom view is much like any other well-designed class. It encapsulates a specific set of functionality with an easy to use interface, it uses CPU and memory efficiently, and so on. In addition to being a well-designed class, though, a custom view should: Conform to Android standards.
References in XML Thus, it is possible to combine color resources with the other simple resources in the XML file under one element: <resources>, but I don't recommend this practice. On the other hand ? attr is a reference to the theme attribute.
What is the name of the file which is used to declare custom attributes? Create an XML res/values/attrs. xml file to define new attributes alongwith their data type.
Change your xml to:
...
<mycustomview id="@+id/cv_1" xyz:nextviewId="@+id/cv_2"... />
<mycustomview id="@+id/cv_2" xyz:nextviewId="@+id/cv_3"... />
...
(note the @+id
in nextviewId
)
This will work on Android 1.6+ (Api Level 4+). Exactly the same approach is used in RelativeLayout
s.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With