I’m trying to create a custom button with text beside it. I’m going to have a list of items with a (x) beside them, so the user can hit the (x) to delete the item. Like this…
(x)Item1 (x)Item2 (x)Item3
I have a class that extends button, but I’m not sure what methods I’m supposed to override, because when I create a button using the custom class, it shows up as a normal button. Here’s my code.
public class LabelButton extends Button {
private final Context context;
private final String label;
public LabelButton( Context context, String label ) {
super( context );
this.context = context;
this.label = label;
}
public View getView( View convertView, ViewGroup parent ) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View labelView = inflater.inflate( R.layout.label, parent, false );
TextView textView = (TextView) labelView.findViewById( R.id.label );
Button button = (Button) labelView.findViewById( R.id.buttonCancel );
textView.setText( "X" );
return labelView;
}
}
You should override onDraw method and constructor with Attrs params