に動的複数を正常に追加しましtogglebutton
たactivity
。しかし、私はsetOnCheckedChangeListener
それぞれの処理に行き詰まっていtogglebutton
ます。
デモ コード スニペットを作成しました。
linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
for (int i = 0; i < 6; i++) {
el = new LinearLayout(this);
el.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams emailLinearParams = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
el.setLayoutParams(emailLinearParams);
el.setPadding(5, 5, 5, 5);
LinearLayout.LayoutParams emailTxtParams = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 0.9f);
TextView emailTxt = new TextView(this);
emailTxt.setText("demo");
emailTxt.setLayoutParams(emailTxtParams);
emailTxt.setGravity(Gravity.CENTER_VERTICAL);
el.addView(emailTxt);
ToggleButton toggleEmailBtn = new ToggleButton(this);
LinearLayout.LayoutParams emailToggleBtnParams = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.1f);
toggleEmailBtn.setLayoutParams(emailToggleBtnParams);
el.addView(toggleEmailBtn);
linearLayout.addView(el);
}