views:

230

answers:

2

I want to create a custom field on which I can place more than one line of text as well as images. And the field can be used like a button(onclick event etc.)

+3  A: 

Hi!
What Thomas suggested is probably enough for you, but in case you want to create your own custom widget you could extend existing ViewGroup class - for example LinearLayout. You could make a "composite view" by adding views you want to your extended LinearLayout.Take a look at the example below


public class MyCompositeView extends LinearLayout implements OnClickListener{

   public MyCompositeView(Context context, AttributeSet attrs) {
   mForwardArrow = new ImageButton(context);
   mForwardArrow.setOnClickListener(mOnDownClickListener);

   mBackArrow = new ImageButton(context);
   mBackArrow.setOnClickListener(mOnUpClickListener);

   mFrameSwitcher = new FrameSwitcherView(context, attr_orientation);
   ...

   LayoutParams lp = LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
   addView(mForwardArrow, lp);
   addView(mFrameSwitcher, lp);
   addView(mBackArrow, lp);
   ...

    }
}

Your component could implement OnClickListener, so you could add your own custom click listeners etc. This approach is more time consuming, but it gives you flexibility.
Regards!

Ramps
+2  A: 

An Android Button already allows multiple lines of text; it automatically gets wrapped as required.

As for adding an image, you should be able to use a standard Button and then set a drawable using the android:drawableLeft property to draw an image next to (to the left of, in this case) the text.

Christopher