私がやろうとしていること:
カスタムアラートダイアログを作成します。他のアラートダイアログと同じようにボタンがありますが、上記は2つのテキストエディット入力ボックスです。カスタムダイアログではなく、カスタマイズされたアラートダイアログを作成したい
これが私が試していることです#3: http ://developer.android.com/guide/topics/ui/dialogs.html
それは言う:
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();
ドキュメントによると:
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
ここで、最初のパラメーターはレイアウトリソースIDで、2番目のパラメーターはルートビューのIDです。
問題は、レイアウトルートが何であるかわからないことです。これは、アクティビティで開始するダイアログです。アクティビティの場合、レイアウトIDを使用する必要がありますか?layout_rootは帽子から引き出されていますか?
また試した:
View layout = inflater.inflate(R.layout.my_custom_layout,
(ViewGroup) findViewById(android.R.id.content).getRootView());
結果のnullポインタ。