如何将片段列表添加到DialogFragment中?

时间:2012-10-08 09:38:53

标签: android android-dialogfragment

我遇到了DialogFragment

的问题

例如我有一个Fragment列表,我想将所有这些片段添加到DialogFragment中并在用户点击按钮时发出警报,有人有任何想法

我在此页面上尝试此操作:http://developer.android.com/guide/components/fragments.html

public static class DetailsFragment extends Fragment {

    public static DetailsFragment newInstance(int index) {
        DetailsFragment f = new DetailsFragment();

        // Supply index input as an argument.
        Bundle args = new Bundle();
        args.putInt("index", index);
        f.setArguments(args);

        return f;
    }

    public int getShownIndex() {
        return getArguments().getInt("index", 0);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        if (container == null) {
            return null;
        }

        ScrollView scroller = new ScrollView(getActivity());
        TextView text = new TextView(getActivity());
        int padding = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                4, getActivity().getResources().getDisplayMetrics());
        text.setPadding(padding, padding, padding, padding);
        scroller.addView(text);
        text.setText(Shakespeare.DIALOGUE[getShownIndex()]);
        return scroller;
    }
}

请帮助:)

0 个答案:

没有答案