【问题标题】:show dialog on fragment在片段上显示对话框
【发布时间】:2014-04-11 22:03:02
【问题描述】:

我必须在片段中显示一个对话框。 DialogFragment的代码是:

public class DialogSintesi extends DialogFragment {

private TextView brownModelli;
private TextView brownArticoli;
private TextView blankModelli;
private TextView blankArticoli;
private TextView pedModelli;
private TextView pedArticoli;

public DialogSintesi() {

}

public static DialogFragment newInstance(String title) {
    DialogFragment fragment = new DialogFragment();
    Bundle args = new Bundle();
    args.putString("title", title);
    fragment.setArguments(args);
    return fragment;
}

@Override    
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.popup_campagne_salvate, container);

    TextView brownModelli = (TextView) view.findViewById(R.id.textBrownModelliNumero);
    TextView brownArticoli = (TextView) view.findViewById(R.id.textBrownArticoliNumero);
    TextView blankModelli = (TextView) view.findViewById(R.id.textBlankModelliNumero);
    TextView blankArticoli = (TextView) view.findViewById(R.id.textBlankArticoliNumero);
    TextView pedModelli = (TextView) view.findViewById(R.id.textPedModelliNumero);
    TextView pedArticoli = (TextView) view.findViewById(R.id.textPedArticoliNumero);

    getDialog().setTitle("Sintesi Campagna");

    return view;
}

}

我尝试将对话框显示到自定义数组适配器中(在列表视图中按下按钮)

info.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View arg0) {

            showDialogSintesi();
        }

    });

而showDialogSintesi的方法是:

public void showDialogSintesi(String nome) {
    android.app.FragmentManager fm = fragment.getFragmentManager();
    DialogFragment dialog = DialogSintesi.newInstance("Info");
    dialog.show(fm,"");

}

我尝试显示此对话框,但它有很多小时都不起作用! 对不起我的英语不好。 太棒了

【问题讨论】:

  • 你在哪里声明你info组件?
  • 有什么问题?它没有编译或对话框没有出现?您的方法showDialogSintesi 应该接受一个字符串,但您从未在注册到您的info 对象的OnClickListener 中向其传递任何内容
  • 是的,我已经声明了图像视图信息。抱歉,showDialogSintesi 方法不应该采用字符串(是一种没有参数的方法)。它不会编译

标签: java android android-fragments android-dialog


【解决方案1】:

检查你是否在使用 android.support.v4.app 或 android.app 在您的代码中一致地导入和声明片段相关变量。

【讨论】:

  • 我使用过 android.support.v4.app.DialogFragment。我尝试更改库,但它不起作用
【解决方案2】:

尝试用 onCreateDialog 替换 onCreateView:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    View view = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
            R.layout.popup_campagne_salvate, container);

    TextView brownModelli = (TextView) view.findViewById(R.id.textBrownModelliNumero);
    TextView brownArticoli = (TextView) view.findViewById(R.id.textBrownArticoliNumero);
    TextView blankModelli = (TextView) view.findViewById(R.id.textBlankModelliNumero);
    TextView blankArticoli = (TextView) view.findViewById(R.id.textBlankArticoliNumero);
    TextView pedModelli = (TextView) view.findViewById(R.id.textPedModelliNumero);
    TextView pedArticoli = (TextView) view.findViewById(R.id.textPedArticoliNumero);

    builder.setView(view);
    builder.setTitle("Sintesi Campagna");

    Dialog dlg = builder.create();
    return dlg;
}

其余的应该和你一样。 您可以在此过程中填充 TextView。

【讨论】:

  • 问题也在showDialogSintesi中,因为它不能编译。上线有问题:dialog.show(fm,"")
  • 对不起,如果我使用 onCreateDialog,我没有容器
  • 没有容器是什么意思?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-20
  • 1970-01-01
  • 1970-01-01
  • 2015-01-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多