如何将图像动态加载到android
中的对话框中public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.popup, null));
}
我只能将静态按钮和图像链接到视图中。
如果我尝试动态链接图像
ImageView image = (ImageView) getActivity().findViewById(R.id.image);
image.setImageResource(R.drawable.icon);
图像作为空对象返回
答案 0 :(得分:1)
这是解决方案
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
ViewGroup vg = (ViewGroup)inflater.inflate(R.layout.popup, null);
ImageView image = (ImageView) vg.findViewById(R.id.image);
image.setImageResource(R.drawable.icon);
builder.setView(vg);
}
希望这有帮助!