显示多个XML意见W / O片段 [英] Displaying multiple xml views w/o fragments

查看:153
本文介绍了显示多个XML意见W / O片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,用户旋转旋转木马。在选定的项目,我需要显示每个项目一个单独的XML视图。轮播是在看得到在与视图的上半部分可见底部的所有时间。我认为有一个更好的办法,而不是使用片段。有任何想法吗?下面code不是以现在的功能,但我觉得充气可能会去,但把它做是困扰我的方式。 case0后出现第1种情况,case5。

  carousel.setOnItemSelectedListener(新OnItemSelectedListener(){        公共无效onItemSelected(CarouselAdapter<>母公司,观景,
                INT位置,长的id){            开关(位置){
            情况下0:
                最后查看的firstView;
                LayoutInflater吹气=(LayoutInflater)getBaseContext()getSystemService(Context.LAYOUT_INFLATER_SERVICE)。
                的firstView = inflater.inflate(R.layout.selected_item,NULL);
                打破;
            情况1:


解决方案

在万一别人运行到这个问题,我解决它:

  LayoutInflater吹气=(LayoutInflater)CarouselActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            的LinearLayout inflateView =(的LinearLayout)findViewById(R.id.InflateParent);
            查看新思维= NULL;            开关(位置){
            情况下0:
                的System.out.println(案0);
                inflateView.removeAllViews();
                新思维= inflater.inflate(R.layout.nextview,NULL);
                inflateView.addView(新思维);

In my app the user spins a carousel. On the selected Item I need to display a separate xml view for each item. The carousel is visibile at all time at the bottom with the view visible in the top half. I think that there is a better way than to use fragments. Any ideas? The following code is not functional as of now but I think an inflator may be the way to go but to get it done is troubling me. After case0 there is case1-case5.

 carousel.setOnItemSelectedListener(new OnItemSelectedListener(){

        public void onItemSelected(CarouselAdapter<?> parent, View view,
                int position, long id) {



            switch(position){
            case 0:
                final View firstview;
                LayoutInflater inflater = (LayoutInflater)   getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
                firstview = inflater.inflate(R.layout.selected_item, null);
                break;
            case 1:

解决方案

In case anyone else runs into this problem I solved it:

    LayoutInflater inflater = (LayoutInflater) CarouselActivity.this.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
            LinearLayout inflateView = (LinearLayout) findViewById( R.id.InflateParent );
            View nextView = null;

            switch(position){
            case 0:
                System.out.println("Case 0");
                inflateView.removeAllViews();
                nextView = inflater.inflate( R.layout.nextview, null );
                inflateView.addView(nextView);

这篇关于显示多个XML意见W / O片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆