I can create this by using XML. But here my requirement is if I set attribute show_stepCount=3, then 3 views should be drawn on the canvas. I should be able to select one item at a time. I am not able to understand should I inherit my custom class by View or with some other view type to achieve the below UI.
Related
I have a custom view consisting of imageview and textview. Lets call it CustomViewA. I would like to add several instances of this view to another custom view (CustomViewB) in random positions like so:
How can I say in CustomViewB, something like canvas.drawLayout(new CustomViewA(text, imageBackground), x,y)??? I.e. draw CustomViewA in specific (x,y) position inside CustomViewB?And then manipulate this CustomViewA like I would any Shape on touching,dragging, etc? If I would make CustomViewB custom Layout how can I overwrite onLayout(), onMeasure(), taking into account that CustomViewA-s don't relate to each other in any way?
So, I have the basic structure of creating a custom android view component locked down (i.e. create the view's layout xml, create a class for that view that references the layout xml, and then use the class name in an layout xml that uses the custom view) and that's all fine.
However, if I have a set of custom android UI components, can I combine them to create an even bigger custom android UI component? And if so, how would i reference the "inner" custom android UI components in the class that defines the "outer" android UI component?
The real issue here is that the TypedArray Class used to extract values for a custom UI component has only methods for extracting individual attributes (e.g. there is a "getString()" but no "[] getString()" that would return an array of strings that would then be used to update a set of custom UI components at once).
Is it possible in android to create a composite custom android UI component made up of custom android UI components?
(updated: Here is a link. http://postimg.org/image/nbnfq4nlp/2916ab5b/. Here a set of one QRCode Image, time and location TextViews form one Custom View (QRCodeScanItemView) while a group of QRCodeScanItemViews and the prominent date form another View)
I want to create a custom view with some text and two buttons all on one line. I need to be able to add multiple (any number) of these views to an existing layout dynamically (needs to be able to scroll). I want to pass a custom object to the view and set the text and buttons. I need access to the button event handlers from the activity. I've looked a little into custom views but I'm still at a loss for how to do what I want. I'm used to .NET custom controls, and I'm looking for the same effect. Any help or example code would be greatly appreciated.
What you want is custom compound view. You should write you own class (usually extending one of the layouts) and whole behavior, inflate the layout the way you want etc.
More of it: http://developer.android.com/guide/topics/ui/custom-components.html
This one helped me a lot too: http://javatechig.com/android/creating-custom-and-compound-views-in-android-tutorial
If you use list activity or list fragment, you will automatically have the many features you have asked for. You only need to create a adapter class for your listview. You can define your layout for your row view(buttons, text etc..) Try to look at the examples on the web for cusom adapter and lists.
I found the following design in market of my tablet. I want to design a layout as like the below tables containing a image, text and a button for my android app. how to do this
You can achieve simple table look, by setting different colors to rows and cloumns and set appropriate margins in that here is example. Here he sets only border but you can fill any color or drawable inside column.
For this solution, i would suggest you to design custom adapter to be displayed either in GridView or in multi column ListView.
But i think GridView would be best to implement the above functionality.
Now, to define a custom adapter, you just have to create a simple class and extends BaseAdapter, and then you have to override the getView() method inside this class. Now within the getView() method, you can inflate() the custom row layout file (which you define for one item , this item xml layout file represents every items inside the GridView).
Here is the simple example for implementing a simple GridView.
For the detailed exmmple of such gridview, refer this example: Android - GridView example
I have to dynamically add a list of views (the views use RelativeLayout). Can I do this by specifying the view definition in xml and instantiate multiple objects off it? This gives the usual benefits of separating the view part from the code (for e.g., making it easy for the UI guys to alter things) or Is going the ArrayAdapter the suggested/only route?
are you saying that you want to do this?
View v1 = (View) findViewById(R.id.someView);
View v2 = (View) findViewById(R.id.someView);
If you do this, you will merely have 2 references to the same view; it does not create two separate View objects. However, if you want to make a vertical list of views, look into ListActivity. in this case you will make a layout xml that will be used for every item in the list. you will need to implement a ListAdapter, or use a SimpleArrayAdapter.
does that help?