Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 带自定义ListView的DialogFragment大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试创建一个DialogFragment,它显示一个带有自定义ListView的对话框.
public class MultiSELEctDialogCustom extends DialogFragment {


    ListView mLOCATIOnList;
    private ArrayList<String> mOfficeListItems = new ArrayList<String>();


    public static MultiSELEctDialogCustom newInstance(int titlE) {
        MultiSELEctDialogCustom dialog = new MultiSELEctDialogCustom();
        Bundle args = new Bundle();
        args.puTint("title",titlE);
        dialog.setArguments(args);
        return dialog;
    }

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

        Collections.addAll(mOfficeListItems,getresources().getStringArray(R.array.offices)); 
        View v = inflater.inflate(R.layout.fragment_choice_list,container,truE);

        mLOCATIOnList = (ListView)v.findViewById(R.id.LOCATIOn_criteria_list);

        final FunctionListArrayAdapter adapter = new FunctionListArrayAdapter(
                this,android.R.layout.simple_list_item_1,mOfficeListItems);
        mLOCATIOnList.setAdapter(adapter);

        getDialog().settitle(getArguments().geTint("title"));

        return v;
    }


}@H_403_3@ 
 

从片段中调用时:

@H_152_2@multiSELEctDialogCustom dialogFrag = MultiSELEctDialogCustom_.newInstance(R.String.dialog_titlE); dialogFrag.show(getActivity().getSupportFragmentManager(),@R_607_6633@@H_403_3@

它只显示一个带有标题的空白对话框…为什么我的列表@L_616_10@?

解决方法

你应该重写onCreateDialog而不是使用onCreateView,它应该看起来像:
@Override
public Dialog onCreateDialog(Bundle savedInstanceStatE) {
    Collections.addAll(mOfficeListItems,getresources().getStringArray(R.array.offices)); 
    View v = getActivity().getLayoutInflater().inflate(R.layout.fragment_choice_list,@R_607_6633@

    mLOCATIOnList = (ListView)v.findViewById(R.id.LOCATIOn_criteria_list);

    final FunctionListArrayAdapter adapter = new FunctionListArrayAdapter(
            this,mOfficeListItems);
    mLOCATIOnList.setAdapter(adapter);

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

    builder.settitle(getArguments().geTint("title")).setView(v);

    return builder.create();
}@H_403_3@ 
 

DialogFragment documentation page的引用描述了您要做的事情:

你的情况下,似乎onCreateDialog是你想要做自定义内部视图的方法.

大佬总结

以上是大佬教程为你收集整理的android – 带自定义ListView的DialogFragment全部内容,希望文章能够帮你解决android – 带自定义ListView的DialogFragment所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。