Which method fires when creating an AlertDialog ?
As onCreate()for operations, My case: I have a fragment, and in this fragment I have a button using this method setOnClickListener():
btnAddPromotionAw.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(
getActivity());
LayoutInflater inflater = (LayoutInflater) getActivity()
.getSystemService(getActivity().LAYOUT_INFLATER_SERVICE);
View dialog = inflater.inflate(R.layout.promotion_aware_picker,
null);
builder.setView(dialog);
final AlertDialog alertDialog = builder.create();
alertDialog.show();
alertDialog.getWindow().setLayout(600,400);
}
});
I want to execute the below code only on creating an AlertDialog:
ArrayList<Goods> Goodslist = new ArrayList<Goods>();
Goodslist = promotionAwAccess
.getGoodsByIsMerch();
LinearLayout ll1 = (LinearLayout) alertDialog
.findViewById(R.id.linearLayoutPAGoods);
final RadioButton[] rdb = new RadioButton[Goodslist.size()];
RadioGroup rdg = new RadioGroup(getActivity());
rdg.setOrientation(RadioGroup.VERTICAL);
rdg.setGravity(Gravity.RIGHT);
for (int i = 0; i < Goodslist.size(); i++) {
rdb[i] = new RadioButton(getActivity());
rdg.addView(rdb[i]);
rdb[i].setText(Goodslist.get(i)
.getGoodsName());
rdb[i].setId(i);
rdb[i].setButtonDrawable(android.R.color.transparent);
rdb[i].setCompoundDrawablesWithIntrinsicBounds(
0, 0, R.drawable.btn_radio_custom,
0);
}
ll1.addView(rdg);
Sorry for the incomplete explanation first.
source
share