【问题标题】:Dynamically load an image into a dialog box将图像动态加载到对话框中
【发布时间】:2013-02-06 20:49:47
【问题描述】:

如何将图像动态加载到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);

图像作为空对象返回

【问题讨论】:

  • 您在哪个位置获得对 Image findViewById(R.id.image) 的引用; ?

标签: android dialog android-dialogfragment


【解决方案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);
}

希望这会有所帮助!

【讨论】:

  • 它引发了需要调用 requestFeature() 的异常
  • 糟糕,因为我覆盖了 oncreateview 方法。
猜你喜欢
  • 1970-01-01
  • 2022-10-14
  • 1970-01-01
  • 1970-01-01
  • 2019-05-27
  • 1970-01-01
  • 2013-11-08
  • 1970-01-01
  • 2020-04-16
相关资源
最近更新 更多