「Android開発」アラートダイアログ(AlertDialog)をカスタマイズする方法
1.パッケージ無しでAlertDialogを実装
View layout = inflater.inflate(R.layout.enable_agree_dialog,
(ViewGroup) findViewById(R.id.dialog));
new AlertDialog.Builder(this).setTitle(title).setView(layout)
.setPositiveButton(“閉じる", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton(“キャンセル",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
//ボタンキャンセルアクション
}
}).show();
2.パッケージでAlertDialogを実装
public class Dialog_edit extends AlertDialog implements OnClickListener {
private String text = “";
private EditText edit;
private OnDateSetListener mCallback;
private LinearLayout layout;
public interface OnDateSetListener {
void onDateSet(String text);
}
protected Dialog_edit(Context context, String title, String value,
OnDateSetListener Callback) {
super(context);
mCallback = Callback;
TextView label = new TextView(context);
edit = new EditText(context);
edit.setText(value);
layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
// LinearLayout.LayoutParams param =
// new LinearLayout.LayoutParams(100, 40);
// layout.addView(label, param);
LinearLayout.LayoutParams param2 = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
50);
layout.addView(edit, param2);
setView(layout);
setTitle(title);
setButton(“確認", this);
setButton2(“キャンセル", (OnClickListener) null);
}
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
// Log.v(“cola", “U click which=" + which);
text = edit.getText().toString();
if (mCallback != null)
mCallback.onDateSet(text);
}
}