public
class
SelectButton
extends
Button{
protected
Context context;
protected
ArrayList<String> data;
int
item;
public
SelectButton(Context context, AttributeSet attrs) {
super
(context, attrs);
this
.context = context;
item = attrs.getAttributeResourceValue(
null
,
"item"
,
0
);
inflate(context, item,
null
);
setOnClickListener(
new
OnClickListener() {
@Override
public
void
onClick(View v) {
AlertDialog.Builder ab =
new
AlertDialog.Builder(SelectButton.
this
.context);
final
CharSequence[] list = data.toArray(
new
CharSequence[data.size()]);
ab.setItems(list ,
new
DialogInterface.OnClickListener() {
@Override
public
void
onClick(DialogInterface dialog,
int
which) {
Toast.makeText(SelectButton.
this
.context,
"select : "
+list[which], Toast.LENGTH_LONG).show();
}
});
ab.create().show();
}
});
}