AlertDialog的自定义视图

时间:2014-04-02 06:33:34

标签: android alertdialog android-alertdialog viewgroup

我正在尝试为AlertDialog应用自定义视图。我的问题是我使用fragmentlistview使用了自定义适配器,而alertdialog我认为它正在使用ViewGroup混淆了。

这是我对alertdialog所拥有的东西,但是它一直在崩溃给我一个

  适配器视图

不支持

unsupportedoperationexception addview

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if(item.getItemId() == R.id.action_add) {
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View dialoglayout = inflater.inflate(R.layout.dialog_new_site, (ViewGroup)getActivity().getCurrentFocus());
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
        alertDialogBuilder.setView(dialoglayout);

3 个答案:

答案 0 :(得分:0)

试试这个:

View dialoglayout = getActivity().getLayoutInflater().inflate(R.layout.dialog_new_site, null);

答案 1 :(得分:0)

尝试这样做

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    view v = inflater.inflate(R.layout.dialog_layout, null);

答案 2 :(得分:0)

尝试创建自定义警报对话框并使用它。

public class MyAlertDialog  extends Dialog {

  Context mContext;

  public InfoCustomDialog(Context context, int theme) {
    super(context, theme);
    this.mContext = context;
   }



   @Override
   protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
            setContentView(R.layout.dialog_new_site);
  }
 }

然后使用

  MyAlertDialog alertDialog = new MyAlertDialog(getActivity());
  alertDialog.show();