我正试图在我的警告对话框中给自定义布局充气,这给了我一个奇怪的例外。
活动中的代码
setContentView(R.layout.blank);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View v = getLayoutInflater().inflate(R.layout.activity, null);
builder.setView(v);
builder.show();
更新
我发现我得到的context
不是它的警报对象,所以它在这里崩溃
View rowView = LayoutInflater.from(context).inflate(R.layout.activity_calendar, null);
如何解决这个问题?
崩溃日志
12-28 23:57:32.070: E/AndroidRuntime(17285): FATAL EXCEPTION: main
12-28 23:57:32.070: E/AndroidRuntime(17285): java.lang.IllegalArgumentException: No view found for id 0x7f080007 for fragment ScreenSlidePageFragment{417d8500 #0 id=0x7f080007}
12-28 23:57:32.070: E/AndroidRuntime(17285): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:822)
12-28 23:57:32.070: E/AndroidRuntime(17285): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1032)
答案 0 :(得分:0)
变化:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
要:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());