Reputation: 2300
I would like to create a custom and composite view in android. My custom view will include 1 textview, 5 radiobuttons two buttons and some images. I don't know how to do it. if there would be some example or code spinet, it would be nice..
Upvotes: 2
Views: 7980
Reputation: 1401
you might want to read about the extended class' constructors here: Do I need all three constructors for an Android custom view?
Upvotes: 2
Reputation: 626
I think it could help you:
First you can define a RelativeLayout in xml, with all the elements you want on it, placed like you want.
Second, when you have that layout defined, you can develop a custom class, extending RelativeLayout, and inflate that layout in the constructor method of the class, something like this:
public class MyCustomView extends RelativeLayout {
...
public MyCustomView(Context context) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
addView(inflater.inflate(R.layout.your_layout, null));
oneTextView = (TextView) findViewById(R.id.oneTextView);
oneRadioButton = (RadioButton) findViewById(R.id.oneRadioButton);
...
}
...
}
At this point, you can use oneTextView, oneRadioButton, etc., in your class in a normal way.
Upvotes: 18