アクティビティ内からではなく、Java クラス内で次のことを行っています。
LinearLayout buttonLayout = (LinearLayout) parentContext.getLayoutInflater().inflate(R.layout.app_dialog, null);
Button btnSignIn = (Button) parentContext.findViewById(R.id.BTN_ID_SIGN_IN);
Button btnCancel = (Button) parentContext.findViewById(R.id.BTN_ID_CANCEL);
btnSignIn.setOnClickListener(new OnClickListener(){
public void onClick(View v) { ... }});
レイアウト xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/footer" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_alignParentBottom="true" style="@android:style/ButtonBar" >
<Button android:id="@+id/BTN_ID_SIGN_IN" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:text="@string/em_btn_signin" />
<Button android:id="@+id/BTN_ID_CANCEL" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:text="@string/em_btn_cancel" />
</LinearLayout>
最後の行は NPE をスローしています。onClickListener なしでコードを試すと、ボタンが完全に表示されます (ボタンをタップしても何も起こりません)。ボタンに何も設定できないのはなぜですか?