如何在启动画面时加载活动

时间:2017-03-19 16:35:00

标签: java android html android-layout

我有一个包含7张幻灯片的viewpager。但幻灯片的内容是HTML,所以我想在启动画面中加载HTML的数据,之后我想显示内容。我的内容在我的活动的instantiateItem方法中得到了膨胀。

@Override
    public Object instantiateItem(ViewGroup container, int position) {


        layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        HTMLPre preparer = new HTMLPre();

        String font = "SourceSansPro-Regular";


        View one = layoutInflater.inflate(R.layout.slide_type_a, container, false);


        WebView header_1_a = (WebView) one.findViewById(R.id.header_slide_type_a_1);
        preparer.loadHTLMContentHeader(getString(R.string.Aktien1_header),header_1_a,font);
        ImageView image_1_a = (ImageView) one.findViewById(R.id.image_slide_type_a_1);
        image_1_a.setImageResource(R.drawable.picture_kap01_01);
        WebView text_1_a = (WebView) one.findViewById(R.id.text_slide_type_a_1);
        preparer.loadHTLMContentText(getString(R.string.Aktien1), text_1_a,font);

        View two = layoutInflater.inflate(R.layout.slide_type_a, container, false);


        header_1_a = (WebView) two.findViewById(R.id.header_slide_type_a_1);
        preparer.loadHTLMContentHeader(getString(R.string.Aktien2_header),header_1_a,font);
        image_1_a = (ImageView) two.findViewById(R.id.image_slide_type_a_1);
        image_1_a.setImageResource(R.drawable.picture_kap01_01);
        text_1_a = (WebView) two.findViewById(R.id.text_slide_type_a_1);
        preparer.loadHTLMContentText(getString(R.string.Aktien2), text_1_a,font);


        View three = layoutInflater.inflate(R.layout.slide_type_a, container, false);

        header_1_a = (WebView) three.findViewById(R.id.header_slide_type_a_1);
        preparer.loadHTLMContentHeader(getString(R.string.Aktien3_header), header_1_a,font);
        image_1_a = (ImageView) three.findViewById(R.id.image_slide_type_a_1);
        image_1_a.setImageResource(R.drawable.boerse_antwerpen);
        text_1_a = (WebView) three.findViewById(R.id.text_slide_type_a_1);
        preparer.loadHTLMContentText(getString(R.string.Aktien3), text_1_a,font);


        View four = layoutInflater.inflate(R.layout.slide_type_a, container, false);

        header_1_a = (WebView) four.findViewById(R.id.header_slide_type_a_1);
        preparer.loadHTLMContentHeader(getString(R.string.Aktien4_header), header_1_a,font);
        image_1_a = (ImageView) four.findViewById(R.id.image_slide_type_a_1);
        image_1_a.setImageResource(R.drawable.parketthandel);
        text_1_a = (WebView) four.findViewById(R.id.text_slide_type_a_1);
        preparer.loadHTLMContentText(getString(R.string.Aktien4), text_1_a,font);



        View five = layoutInflater.inflate(R.layout.slide_type_c, container, false);

        image_1_a = (ImageView) five.findViewById(R.id.image_slide_type_c_1);
        image_1_a.setImageResource(R.drawable.parketthandel);
        text_1_a = (WebView) five.findViewById(R.id.text_slide_type_c_1);
        preparer.loadHTLMContentText(getString(R.string.Aktien5), text_1_a,font);




        View six = layoutInflater.inflate(R.layout.slide_type_c, container, false);

        image_1_a = (ImageView) six.findViewById(R.id.image_slide_type_c_1);
        image_1_a.setImageResource(R.drawable.parketthandel);
        text_1_a = (WebView) six.findViewById(R.id.text_slide_type_c_1);
        preparer.loadHTLMContentText(getString(R.string.Aktien6), text_1_a,font);


        View seven = layoutInflater.inflate(R.layout.slide_type_c, container, false);

        image_1_a = (ImageView) seven.findViewById(R.id.image_slide_type_c_1);
        image_1_a.setImageResource(R.drawable.parketthandel);
        text_1_a = (WebView) seven.findViewById(R.id.text_slide_type_c_1);
        preparer.loadHTLMContentText(getString(R.string.Aktien7), text_1_a,font);

        View eigth = layoutInflater.inflate(R.layout.slide_type_c, container, false);

        image_1_a = (ImageView) eigth.findViewById(R.id.image_slide_type_c_1);
        image_1_a.setImageResource(R.drawable.seewegevoc);
        text_1_a = (WebView) eigth.findViewById(R.id.text_slide_type_c_1);
        preparer.loadHTLMContentText(getString(R.string.Aktien8), text_1_a,font);



        View nine = layoutInflater.inflate(R.layout.startquiz_layout, container, false);
        View viewarr[] = {one, two, three, four, five, six, seven, eigth, nine};
        container.addView(viewarr[position]);


        return viewarr[position];

    }

所以现在我想在加载启动画面时加载在此激活中完成的操作。有人有任何想法吗?

1 个答案:

答案 0 :(得分:1)

因此,为了简单起见,我创建了一个小样本应用程序,展示了如何创建它。

我没有复制粘贴这里的所有代码,而是创建了一个Gist,你可以找到here

请注意,此代码只是一个示例,不会处理任何错误处理等问题,并且它不会优化为例如处理大量WebView

我知道它并没有完全使用您的代码,但我不知道HTMLPre是什么,我只是使用WebView中加载网站的默认方式。

编辑:添加了整个Git存储库,因此可以运行完整的示例项目 - 找到它here

相关问题