views:

86

answers:

2

Hello. I want to create a own View which containst two buttons without useing 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:

but when i try this nothing gets displayd

A: 

How are you adding your custom view to your XML layout? You need to use the full package name as in <com.blabla.bla.ViewName android:properties="whatever" />.

Computerish
yes i know that how to write this in xml. The problem is the Viewobject
Bartinger
A: 

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.

Lemonsanver