I want to create a custom View which contains two buttons without using xml.
I tried this:
public class ZoomPlate extends LinearLayout {
private Context context;
private Button plus;
private Button minus;
public ZoomPlate(Context context) {
super(context);
init(context);
}
public ZoomPlate(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context) {
this.context = context;
LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,0);
plus = new Button(context);
plus.setText("Plus");
plus.setLayoutParams(params);
minus = new Button(context);
minus.setText("Minus");
minus.setLayoutParams(params);
setOrientation(LinearLayout.VERTICAL);
addView(plus);
addView(minus);
}
}
so that I can use the ZoomPlate in XML like a button or a textview like:
<at.bartinger.zoomplate.ZoomPlate
android:id="@+id/zoomplate"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
but when i try this nothing gets displayed
It might have something to do with whats set as your content view in your main Activity? Check here:
http://developer.android.com/reference/android/app/Activity.html#setContentView%28int%29
Basically you have to set it from a layout resources or a View.