How to enbbed a GraphicsView into a layout? Or how do I add buttons and textViews to a GraphicsView? Could some one post a simple working example?
-Henry
I don't think you can add other Views inside a View component.
GraphicsView is not a default Android SDK class, so we can't know what you have there, sorry.
Make a Layout component to be able to add View components inside it.
To embed your GraphicsView in a layout in xml use something like:
<com.package.GraphicsView
id="#+id/graphics"
...
/>
Related
I'm developing an android app in Kotlin and I'm using View Binding.
I've included a layout inside a ConstraintLayout, like this:
<include
android:id="#+id/item_salon_profile"
layout="#layout/item_salon_profile"
... />
The included layout has some TextView inside and a background.
The element binding.itemSalonProfile is a ItemSalonProfileBinding (and not a View), so I'm not able to set the listener in the usual way: binding.itemSalonProfile.setOnClickListener{ }.
How can I set an OnClick Listener for the whole included layout?
Thanks.
The solution was as simple as:
binding.root.setOnClickListener{ }
Hello Community i am new and need your expert opinions.
i have custom footer.xml layout with some buttons on it , i want to add this xml to my activity layout, and i also want to implement click listner for button. Need your guidance.enter image description here
i am able to include footer through
<include layout="#layout/footer" />
it includes the footer layout in activity layout, but there are some buttons i also want to implement action for them.is there any way ?
You can use this on your button definition (inside the footer layout)
android:onclick="clickMethodName"
Just ensure that any class that uses that layout implements 'clickMethodName'.
Alternatively, you can set the onClickListener in your class, after finding the button by id.
See the official documentation for more details and examples, right at the top:
http://developer.android.com/reference/android/widget/Button.html
I notice that there is a tag <view>(not <View>) which can be used in Android layout xml. When I add such a tag in a layout xml, the app can be successfully compiled but crashes when running. So what is this <view> used for?
view is an alternative way for specifying a view to inflate. You need to combine it with class attribute to specify the class name.
This is "useful" if your view class is an inner class and you cannot use something with a $ in the tag name in XML. (Having inner classes as Views you inflate is not a very good idea though.)
For example:
<view class="your.app.full.package.Something$InnerClass" ... />
Reference: http://androidxref.com/5.0.0_r2/xref/frameworks/base/core/java/android/view/LayoutInflater.java#696
View is widget of android that is use to add any kind of view.Like in problems when we use scrollView in a activity and at bottom of activity there is buttons ,That time we add view to looks better.We can set any kind of color to View .
for exp
This will make a View of 20dp height.
Regarding this example -
http://android-coding.blogspot.com/2011/05/detect-multi-touch-event-test-on-custom.html
How can I add EditText to the view ?
I tried to add it to the layout but when I'm trying to update it I'm getting error message.
Thanks
I found a nice example here - http://www.kellbot.com/2009/06/android-hello-circle.
I added EditText to the layout and its working fine.
In order to use this example the code should be written as explained in Sebastien's comment, in which he uses parent as described in this line:
final Activity parent = this;
The MultiTouchView from the link extends a View. You cannot add other Views to a View. You will need the MultiTouchView to extend a ViewGroup. See the android doc on building custom components.
To be able to add views, I think replacing the following line in the sample code
public class MultiTouchView extends View {
with
public class MultiTouchView extends FrameLayout {
should work because FrameLayout is a subclass of ViewGroup. You may want to chose a different layout depending on your needs.
I'm coming from the world of GWT and UIBinder, where I'm used to defining custom components by extending Composite, and then putting all the UI layout code in a MyComponent.ui.xml file. This is a very nice way to build up components from smaller pieces.
I'm trying to achieve the same effect on Android with custom Views. I've been able to programmatically extend View, and then add objects by calling addView(textView). I'd like to be able to do that in XML, but I don't see how to associate an xml layout file with the view (apart the primary res/layout/main.xml file, which provides the primary layout for the app.
How can I layout my custom views in XML?
Edit: My question was unclear. What I'm looking to do is associate a my_widget.xml file with my customized view. Then in my_widget.xml I'd like to define various TextViews, etc, and plug them into my View class.
Use the fully qualified name of your custom view class in place of one of the built-in views. Here's a layout, for instance, that fills the window with your class:
<?xml version="1.0" encoding="utf-8"?>
<my.package.MyCustomView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
To construct Views from XML, use LayoutInflater.
You can use findViewById (int id) with an id defined in XML. See the example in the android doc here (scroll down to IDs).