java.lang.ClassCastException:android.view.ViewGroup $的LayoutParams不能转换为android.widget.Gallery $的LayoutParams [英] java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.Gallery$LayoutParams

查看:189
本文介绍了java.lang.ClassCastException:android.view.ViewGroup $的LayoutParams不能转换为android.widget.Gallery $的LayoutParams的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想补充 Fancycoverflow 在我的应用程序,它工作正常静态图片作为的这个例子

但我没有在适配器的一些变化,我尝试运行我的应用程序,它崩溃和下面的错误显示

 致命异常:主要
  java.lang.ClassCastException:android.view.ViewGroup $的LayoutParams不能转换为android.widget.Gallery $的LayoutParams
    在android.widget.Gallery.setUpChild(Gallery.java:889)
    在android.widget.Gallery.makeAndAddView(Gallery.java:858)
    在android.widget.Gallery.layout(Gallery.java:665)
    在android.widget.Gallery.onLayout(Gallery.java:357)
    在android.view.View.layout(View.java:14118)
    在android.view.ViewGroup.layout(ViewGroup.java:4467)
    在android.widget.LinearLayout.setChildFrame(LinearLayout.java:1670)
    在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1528)
    在android.widget.LinearLayout.onLayout(LinearLayout.java:1441)
    在android.view.View.layout(View.java:14118)
    在android.view.ViewGroup.layout(ViewGroup.java:4467)
    在android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
    在android.view.View.layout(View.java:14118)
    在android.view.ViewGroup.layout(ViewGroup.java:4467)
    在android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
    在android.view.View.layout(View.java:14118)
    在android.view.ViewGroup.layout(ViewGroup.java:4467)
    在android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
    在android.view.View.layout(View.java:14118)
    在android.view.ViewGroup.layout(ViewGroup.java:4467)
    在android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    在android.view.View.layout(View.java:14118)
    在android.view.ViewGroup.layout(ViewGroup.java:4467)
    在android.widget.LinearLayout.setChildFrame(LinearLayout.java:1670)
    在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1528)
    在android.widget.LinearLayout.onLayout(LinearLayout.java:1441)
    在android.view.View.layout(View.java:14118)
    在android.view.ViewGroup.layout(ViewGroup.java:4467)
    在android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    在android.view.View.layout(View.java:14118)
    在android.view.ViewGroup.layout(ViewGroup.java:4467)
    在android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2183)
    在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1947)
    在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)
    在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:4872)
    在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:776)
    在android.view.Choreographer.doCallbacks(Choreographer.java:579)
    在android.view.Choreographer.doFrame(Choreographer.java:548)
    在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:762)
    在android.os.Handler.handleCallback(Handler.java:800)
    在android.os.Handler.dispatchMessage(Handler.java:100)
    在android.os.Looper.loop(Looper.java:194)
    在android.app.ActivityThread.main(ActivityThread.java:5371)
    在java.lang.reflect.Method.invokeNative(本机方法)
    在java.lang.reflect.Method.invoke(Method.java:525)
    在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:833)
    在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    在dalvik.system.NativeStart.main(本机方法)
 

在例如它被给定为

 进口android.app.Activity;
进口android.content.Context;
进口android.content.Intent;
进口android.net.Uri;
进口android.os.Bundle;
进口android.view.Gravity;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.Button;
进口android.widget.ImageView;
进口android.widget.LinearLayout;
进口android.widget.TextView;
进口at.techniku​​m.mti.fancycoverflow.FancyCoverFlow;
进口at.techniku​​m.mti.fancycoverflow.FancyCoverFlowAdapter;
进口at.techniku​​m.mti.fancycoverflow.samples.R;

公共类ViewGroupExample延伸活动{

    // ================================================ =============================
    //超类型覆盖
    // ================================================ =============================

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.layout_inflate_example);

        FancyCoverFlow fancyCoverFlow =(FancyCoverFlow)findViewById(R.id.fancyCoverFlow);
        fancyCoverFlow.setAdapter(新ViewGroupExampleAdapter());
    }

    // ================================================ =============================
    //私有类
    // ================================================ =============================

    私有静态类ViewGroupExampleAdapter扩展FancyCoverFlowAdapter {

        // ================================================ =============================
        //私有成员
        // ================================================ =============================

        私人INT []的图像= {R.drawable.image1,R.drawable.image2,R.drawable.image3,R.drawable.image4,R.drawable.image5,R.drawable.image6,};

        // ================================================ =============================
        //超类型覆盖
        // ================================================ =============================

        @覆盖
        公众诠释getCount将(){
            返回images.length;
        }

        @覆盖
        公共整数的getItem(int i)以{
            返回图像[我]
        }

        @覆盖
        众长getItemId(int i)以{
            返回我;
        }

        @覆盖
        公共查看getCoverFlowItem(INT I,查看reuseableView,ViewGroup中的ViewGroup){
            CustomViewGroup customViewGroup = NULL;

            如果(reuseableView!= NULL){
                customViewGroup =(CustomViewGroup)reuseableView;
            } 其他 {
                customViewGroup =新CustomViewGroup(viewGroup.getContext());
                customViewGroup.setLayoutParams(新FancyCoverFlow.LayoutParams(300,600));
            }

            。customViewGroup.getImageView()setImageResource(this.getItem(ⅰ));
            customViewGroup.getTextView()的setText(的String.Format(档案%D,i)段)。

            返回customViewGroup;
        }
    }

    私有静态类CustomViewGroup扩展的LinearLayout {

        // ================================================ =============================
        //子视图
        // ================================================ =============================

        私人的TextView TextView的;

        私人ImageView的ImageView的;

        私人Button按钮;

        // ================================================ =============================
        //构造函数
        // ================================================ =============================

        私人CustomViewGroup(上下文的背景下){
            超(上下文);

            this.setOrientation(垂直);

            this.textView =新的TextView(上下文);
            this.imageView =新ImageView的(上下文);
            this.button =新按钮(上下文);

            LinearLayout.LayoutParams的LayoutParams =新的LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
            this.textView.setLayoutParams(的LayoutParams);
            this.imageView.setLayoutParams(的LayoutParams);
            this.button.setLayoutParams(的LayoutParams);

            this.textView.setGravity(Gravity.CENTER);

            this.imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            this.imageView.setAdjustViewBounds(真正的);

            this.button.setText(转到GitHub上);
            this.button.setOnClickListener(新OnClickListener(){
                @覆盖
                公共无效的onClick(视图查看){
                    意图I =新的意图(Intent.ACTION_VIEW,Uri.parse(https://davidschreiber.github.com/FancyCoverFlow));
                    。view.getContext()startActivity(ⅰ);
                }
            });

            this.addView(this.textView);
            this.addView(this.imageView);
            this.addView(this.button);
        }

        // ================================================ =============================
        //吸气剂
        // ================================================ =============================

        私人TextView的getTextView(){
            返回的TextView;
        }

        私人ImageView的getImageView(){
            返回ImageView的;
        }
    }
}
 

和我有什么改变,因为按我的要求是

MyAdapter

 私有静态类ViewGroupExampleAdapter扩展FancyCoverFlowAdapter {

 私人LayoutInflater充气;
    公共活性;
    查看六;
    公众的ArrayList< HashMap的<字符串,字符串>> ARR;
    公众的ArrayList< HashMap的<字符串,字符串>>数据;


    公共ViewGroupExampleAdapter(活动homeActivity,ArrayList的< HashMap的<字符串,字符串>> myList中){

        ARR = myList中;
        A = homeActivity;
        充气=(LayoutInflater)a.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    // ================================================ =============================
    //私有成员
    // ================================================ =============================

  //私人INT []的图像= {R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,};

    // ================================================ =============================
    //超类型覆盖
    // ================================================ =============================

    @覆盖
    公众诠释getCount将(){
        返回arr.size();
    }

    @覆盖
    公共对象的getItem(INT位置){
        // TODO自动生成方法存根
        返回的位置;
    }

    @覆盖
    众长getItemId(INT位置){
        // TODO自动生成方法存根
        的System.out.println(位置=+位置);
        返回的位置;
    }

    @覆盖
    公共查看getCoverFlowItem(INT I,查看reuseableView,ViewGroup中的ViewGroup){
        查看VI = reuseableView;
        如果(六== NULL)
            VI = inflater.inflate(R.layout.create_club_inflate,NULL);

        TextView的日期1 =(TextView中)vi.findViewById(R.id.txtDate1);
        TextView的日期=(TextView中)vi.findViewById(R.id.txtDate);
        TextView的team1_name =(TextView中)vi.findViewById(R.id.txtTeamName);
        TextView的team2_name =(TextView中)vi.findViewById(R.id.txtVanue);
        TextView的地面=(TextView中)vi.findViewById(R.id.txt_time);

        HashMap的<字符串,字符串>产品=新的HashMap<字符串,字符串>();
        产物= arr.get(ⅰ);

        的System.out.println(名1 =+ product.get(str_team1_name)+团队2 =
                + product.get(str_team2_obj_name));
        date1.setText(product.get(str_srs));
        date.setText(product.get(str_startdt));
        team1_name.setText(product.get(str_team1_name));
        team1_name.setAlpha(5000);
        team2_name.setText(product.get(str_team2_obj_name));
        team2_name.setAlpha(5000);
    //字样字体= Typeface.createFromAsset(getAssets(),TitilliumText22L006.otf);

        INT []色= {Color.rgb(100,100,100),Color.rgb(255,255,255)};
        浮[] color_position = {0,1};
        TILEMODE tile_mode = TileMode.MIRROR; //或TileMode.REPEAT;
        的LinearGradient lin_grad =新的LinearGradient(0,0,0,50,颜色,color_position,tile_mode);
        着色器shader_gradient = lin_grad;
        team1_name.getPaint()setShader(shader_gradient)。
        team2_name.getPaint()setShader(shader_gradient)。
        //team1_name.setTypeface(font);
    // team2_name.setTypeface(字体);
        ground.setText(product.get(str_grnd));

        product.get(str_sName);
        product.get(str_team2_obj_sName);


        串first_team_id = product.get(str__team1_id);
        串second_team_id = product.get(str_team2_obj_id);

        开关(first_team_id){
        案PAK:
            team1_name.setBackgroundResource(R.drawable.pak);
            打破;
        案阿联酋:
            team1_name.setBackgroundResource(R.drawable.uae);
            打破;
        案AUS:
            team1_name.setBackgroundResource(R.drawable.aus);
            打破;
        案AFG:
            team1_name.setBackgroundResource(R.drawable.afg);
            打破;
        案6:
            team1_name.setBackgroundResource(R.drawable.ban);
            打破;
        案23:
            team1_name.setBackgroundResource(R.drawable.sco);
            打破;
        情况下为2:
            team1_name.setBackgroundResource(R.drawable.ind);
            打破;
        案WI:
            team1_name.setBackgroundResource(R.drawable.wi);
            打破;
        案13:
            team1_name.setBackgroundResource(R.drawable.nz);
            打破;
        案SL:
            team1_name.setBackgroundResource(R.drawable.sl);
            打破;
        案9:
            team1_name.setBackgroundResource(R.drawable.eng);
            打破;
        案27:
            team1_name.setBackgroundResource(R.drawable.ir);
            打破;
        案11:
            team1_name.setBackgroundResource(R.drawable.rsa);
            打破;
        案ZIM:
            team1_name.setBackgroundResource(R.drawable.zim);
            打破;
        案63:
            team1_name.setBackgroundResource(R.drawable.kol_fl);
            打破;
        案62:
            team1_name.setBackgroundResource(R.drawable.mum_fl);
            打破;
        案58:
            team1_name.setBackgroundResource(R.drawable.chn_fl);
            打破;
        案61:
            team1_name.setBackgroundResource(R.drawable.del_fl);
            打破;
        案65:
            team1_name.setBackgroundResource(R.drawable.pun_fl);
            打破;
        案64:
            team1_name.setBackgroundResource(R.drawable.raj_fl);
            打破;
        情况下255:
            team1_name.setBackgroundResource(R.drawable.hyd_fl);
            打破;
        案59:
            team1_name.setBackgroundResource(R.drawable.blr_fl);
            打破;
        默认:
            team1_name.setBackgroundResource(R.drawable.otherflag);
            // h_upcoming.tv_left.setText(STR1);
            打破;
        }

        //第二队

        开关(second_team_id){
        案PAK:
            team2_name.setBackgroundResource(R.drawable.pak);
            打破;
        案阿联酋:
            team2_name.setBackgroundResource(R.drawable.uae);
            打破;
        案AUS:
            team2_name.setBackgroundResource(R.drawable.aus);
            打破;
        案AFG:
            team2_name.setBackgroundResource(R.drawable.afg);
            打破;
        案6:
            team2_name.setBackgroundResource(R.drawable.ban);
            打破;
        案23:
            team2_name.setBackgroundResource(R.drawable.sco);
            打破;
        情况下为2:
            team2_name.setBackgroundResource(R.drawable.ind);
            打破;
        案WI:
            team2_name.setBackgroundResource(R.drawable.wi);
            打破;
        案13:
            team2_name.setBackgroundResource(R.drawable.nz);
            打破;
        案SL:
            team2_name.setBackgroundResource(R.drawable.sl);
            打破;
        案9:
            team2_name.setBackgroundResource(R.drawable.eng);
            打破;
        案27:
            team2_name.setBackgroundResource(R.drawable.ir);
            打破;
        案11:
            team2_name.setBackgroundResource(R.drawable.rsa);
            打破;
        案ZIM:
            team2_name.setBackgroundResource(R.drawable.zim);
            打破;
        案63:
            team2_name.setBackgroundResource(R.drawable.kol_fl);
            打破;
        案62:
            team2_name.setBackgroundResource(R.drawable.mum_fl);
            打破;
        案58:
            team2_name.setBackgroundResource(R.drawable.chn_fl);
            打破;
        案61:
            team2_name.setBackgroundResource(R.drawable.del_fl);
            打破;
        案65:
            team2_name.setBackgroundResource(R.drawable.pun_fl);
            打破;
        案64:
            team2_name.setBackgroundResource(R.drawable.raj_fl);
            打破;
        情况下255:
            team2_name.setBackgroundResource(R.drawable.hyd_fl);
            打破;
        案59:
            team2_name.setBackgroundResource(R.drawable.blr_fl);
            打破;
        默认:
            team1_name.setBackgroundResource(R.drawable.otherflag);
            // h_upcoming.tv_left.setText(STR1);
            打破;
        }

        返回六;

    }
}

      / *私有静态类CustomViewGroup扩展的LinearLayout {

    // ================================================ =============================
    //子视图
    // ================================================ =============================

    私人的TextView TextView的;

    私人ImageView的ImageView的;

    私人Button按钮;

    // ================================================ =============================
    //构造函数
    // ================================================ =============================

    私人CustomViewGroup(上下文的背景下){
        超(上下文);

        this.setOrientation(垂直);

        this.textView =新的TextView(上下文);
        this.imageView =新ImageView的(上下文);
        this.button =新按钮(上下文);

        LinearLayout.LayoutParams的LayoutParams =新的LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
        this.textView.setLayoutParams(的LayoutParams);
        this.imageView.setLayoutParams(的LayoutParams);
        this.button.setLayoutParams(的LayoutParams);

        this.textView.setGravity(Gravity.CENTER);

        this.imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        this.imageView.setAdjustViewBounds(真正的);

        this.button.setText(转到GitHub上);
        this.button.setOnClickListener(新OnClickListener(){
            @覆盖
            公共无效的onClick(视图查看){
                意图I =新的意图(Intent.ACTION_VIEW,Uri.parse(https://davidschreiber.github.com/FancyCoverFlow));
                。view.getContext()startActivity(ⅰ);
            }
        });

        this.addView(this.textView);
        this.addView(this.imageView);
        this.addView(this.button);
    }

    // ================================================ =============================
    //吸气剂
    // ================================================ =============================

    私人TextView的getTextView(){
        返回的TextView;
    }

    私人ImageView的getImageView(){
        返回ImageView的;
    }
} * /
 

解决方案

找到进口android.view.ViewGroup.LayoutParams; 这条线,并替换为进口android.widget.LinearLayout.LayoutParams; 此行

I am trying to add Fancycoverflow in my app,It works fine with static image as given in this example.

but i did some changes in Adapter, and i try to run my app and it crashes and shows following error

  FATAL EXCEPTION: main
  java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.Gallery$LayoutParams
    at android.widget.Gallery.setUpChild(Gallery.java:889)
    at android.widget.Gallery.makeAndAddView(Gallery.java:858)
    at android.widget.Gallery.layout(Gallery.java:665)
    at android.widget.Gallery.onLayout(Gallery.java:357)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1670)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1528)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1441)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1670)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1528)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1441)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2183)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1947)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4872)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
    at android.view.Choreographer.doCallbacks(Choreographer.java:579)
    at android.view.Choreographer.doFrame(Choreographer.java:548)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
    at android.os.Handler.handleCallback(Handler.java:800)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5371)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    at dalvik.system.NativeStart.main(Native Method)

In example it is given as

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import at.technikum.mti.fancycoverflow.FancyCoverFlow;
import at.technikum.mti.fancycoverflow.FancyCoverFlowAdapter;
import at.technikum.mti.fancycoverflow.samples.R;

public class ViewGroupExample extends Activity {

    // =============================================================================
    // Supertype overrides
    // =============================================================================

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.layout_inflate_example);

        FancyCoverFlow fancyCoverFlow = (FancyCoverFlow) findViewById(R.id.fancyCoverFlow);
        fancyCoverFlow.setAdapter(new ViewGroupExampleAdapter());
    }

    // =============================================================================
    // Private classes
    // =============================================================================

    private static class ViewGroupExampleAdapter extends FancyCoverFlowAdapter {

        // =============================================================================
        // Private members
        // =============================================================================

        private int[] images = {R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4, R.drawable.image5, R.drawable.image6,};

        // =============================================================================
        // Supertype overrides
        // =============================================================================

        @Override
        public int getCount() {
            return images.length;
        }

        @Override
        public Integer getItem(int i) {
            return images[i];
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getCoverFlowItem(int i, View reuseableView, ViewGroup viewGroup) {
            CustomViewGroup customViewGroup = null;

            if (reuseableView != null) {
                customViewGroup = (CustomViewGroup) reuseableView;
            } else {
                customViewGroup = new CustomViewGroup(viewGroup.getContext());
                customViewGroup.setLayoutParams(new FancyCoverFlow.LayoutParams(300, 600));
            }

            customViewGroup.getImageView().setImageResource(this.getItem(i));
            customViewGroup.getTextView().setText(String.format("Item %d", i));

            return customViewGroup;
        }
    }

    private static class CustomViewGroup extends LinearLayout {

        // =============================================================================
        // Child views
        // =============================================================================

        private TextView textView;

        private ImageView imageView;

        private Button button;

        // =============================================================================
        // Constructor
        // =============================================================================

        private CustomViewGroup(Context context) {
            super(context);

            this.setOrientation(VERTICAL);

            this.textView = new TextView(context);
            this.imageView = new ImageView(context);
            this.button = new Button(context);

            LinearLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            this.textView.setLayoutParams(layoutParams);
            this.imageView.setLayoutParams(layoutParams);
            this.button.setLayoutParams(layoutParams);

            this.textView.setGravity(Gravity.CENTER);

            this.imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            this.imageView.setAdjustViewBounds(true);

            this.button.setText("Goto GitHub");
            this.button.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://davidschreiber.github.com/FancyCoverFlow"));
                    view.getContext().startActivity(i);
                }
            });

            this.addView(this.textView);
            this.addView(this.imageView);
            this.addView(this.button);
        }

        // =============================================================================
        // Getters
        // =============================================================================

        private TextView getTextView() {
            return textView;
        }

        private ImageView getImageView() {
            return imageView;
        }
    }
}

And what i change as per my requirement is

MyAdapter

private static class ViewGroupExampleAdapter extends FancyCoverFlowAdapter {

 private LayoutInflater inflater;
    public Activity a;
    View vi;
    public ArrayList<HashMap<String, String>> arr;
    public ArrayList<HashMap<String, String>> data;


    public ViewGroupExampleAdapter(Activity homeActivity, ArrayList<HashMap<String, String>> myList) {

        arr = myList;
        a = homeActivity;
        inflater = (LayoutInflater) a.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    // =============================================================================
    // Private members
    // =============================================================================

  //  private int[] images = {R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher,};

    // =============================================================================
    // Supertype overrides
    // =============================================================================

    @Override
    public int getCount() {
        return arr.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        System.out.println("position=" + position);
        return position;
    }

    @Override
    public View getCoverFlowItem(int i, View reuseableView, ViewGroup viewGroup) {
        View vi = reuseableView;
        if (vi == null)
            vi = inflater.inflate(R.layout.create_club_inflate, null);

        TextView date1 = (TextView) vi.findViewById(R.id.txtDate1);
        TextView date = (TextView) vi.findViewById(R.id.txtDate);
        TextView team1_name = (TextView) vi.findViewById(R.id.txtTeamName);
        TextView team2_name = (TextView) vi.findViewById(R.id.txtVanue);
        TextView ground = (TextView) vi.findViewById(R.id.txt_time);

        HashMap<String, String> product = new HashMap<String, String>();
        product = arr.get(i);

        System.out.println("name 1= " + product.get("str_team1_name") + " team 2="
                + product.get("str_team2_obj_name"));
        date1.setText(product.get("str_srs"));
        date.setText(product.get("str_startdt"));
        team1_name.setText(product.get("str_team1_name"));
        team1_name.setAlpha(5000);
        team2_name.setText(product.get("str_team2_obj_name"));
        team2_name.setAlpha(5000);
    //  Typeface font = Typeface.createFromAsset(getAssets(), "TitilliumText22L006.otf");

        int[] color = { Color.rgb(100, 100, 100), Color.rgb(255, 255, 255) };
        float[] color_position = { 0, 1 };
        TileMode tile_mode = TileMode.MIRROR; // or TileMode.REPEAT;
        LinearGradient lin_grad = new LinearGradient(0, 0, 0, 50, color, color_position, tile_mode);
        Shader shader_gradient = lin_grad;
        team1_name.getPaint().setShader(shader_gradient);
        team2_name.getPaint().setShader(shader_gradient);
        //team1_name.setTypeface(font);
    //  team2_name.setTypeface(font);
        ground.setText(product.get("str_grnd"));

        product.get("str_sName");
        product.get("str_team2_obj_sName");


        String first_team_id = product.get("str__team1_id");
        String second_team_id = product.get("str_team2_obj_id");

        switch (first_team_id) {
        case "PAK":
            team1_name.setBackgroundResource(R.drawable.pak);
            break;
        case "UAE":
            team1_name.setBackgroundResource(R.drawable.uae);
            break;
        case "AUS":
            team1_name.setBackgroundResource(R.drawable.aus);
            break;
        case "AFG":
            team1_name.setBackgroundResource(R.drawable.afg);
            break;
        case "6":
            team1_name.setBackgroundResource(R.drawable.ban);
            break;
        case "23":
            team1_name.setBackgroundResource(R.drawable.sco);
            break;
        case "2":
            team1_name.setBackgroundResource(R.drawable.ind);
            break;
        case "WI":
            team1_name.setBackgroundResource(R.drawable.wi);
            break;
        case "13":
            team1_name.setBackgroundResource(R.drawable.nz);
            break;
        case "SL":
            team1_name.setBackgroundResource(R.drawable.sl);
            break;
        case "9":
            team1_name.setBackgroundResource(R.drawable.eng);
            break;
        case "27":
            team1_name.setBackgroundResource(R.drawable.ir);
            break;
        case "11":
            team1_name.setBackgroundResource(R.drawable.rsa);
            break;
        case "ZIM":
            team1_name.setBackgroundResource(R.drawable.zim);
            break;
        case "63":
            team1_name.setBackgroundResource(R.drawable.kol_fl);
            break;
        case "62":
            team1_name.setBackgroundResource(R.drawable.mum_fl);
            break;
        case "58":
            team1_name.setBackgroundResource(R.drawable.chn_fl);
            break;
        case "61":
            team1_name.setBackgroundResource(R.drawable.del_fl);
            break;
        case "65":
            team1_name.setBackgroundResource(R.drawable.pun_fl);
            break;
        case "64":
            team1_name.setBackgroundResource(R.drawable.raj_fl);
            break;
        case "255":
            team1_name.setBackgroundResource(R.drawable.hyd_fl);
            break;
        case "59":
            team1_name.setBackgroundResource(R.drawable.blr_fl);
            break;
        default:
            team1_name.setBackgroundResource(R.drawable.otherflag);
            // h_upcoming.tv_left.setText(str1);
            break;
        }

        // second team

        switch (second_team_id) {
        case "PAK":
            team2_name.setBackgroundResource(R.drawable.pak);
            break;
        case "UAE":
            team2_name.setBackgroundResource(R.drawable.uae);
            break;
        case "AUS":
            team2_name.setBackgroundResource(R.drawable.aus);
            break;
        case "AFG":
            team2_name.setBackgroundResource(R.drawable.afg);
            break;
        case "6":
            team2_name.setBackgroundResource(R.drawable.ban);
            break;
        case "23":
            team2_name.setBackgroundResource(R.drawable.sco);
            break;
        case "2":
            team2_name.setBackgroundResource(R.drawable.ind);
            break;
        case "WI":
            team2_name.setBackgroundResource(R.drawable.wi);
            break;
        case "13":
            team2_name.setBackgroundResource(R.drawable.nz);
            break;
        case "SL":
            team2_name.setBackgroundResource(R.drawable.sl);
            break;
        case "9":
            team2_name.setBackgroundResource(R.drawable.eng);
            break;
        case "27":
            team2_name.setBackgroundResource(R.drawable.ir);
            break;
        case "11":
            team2_name.setBackgroundResource(R.drawable.rsa);
            break;
        case "ZIM":
            team2_name.setBackgroundResource(R.drawable.zim);
            break;
        case "63":
            team2_name.setBackgroundResource(R.drawable.kol_fl);
            break;
        case "62":
            team2_name.setBackgroundResource(R.drawable.mum_fl);
            break;
        case "58":
            team2_name.setBackgroundResource(R.drawable.chn_fl);
            break;
        case "61":
            team2_name.setBackgroundResource(R.drawable.del_fl);
            break;
        case "65":
            team2_name.setBackgroundResource(R.drawable.pun_fl);
            break;
        case "64":
            team2_name.setBackgroundResource(R.drawable.raj_fl);
            break;
        case "255":
            team2_name.setBackgroundResource(R.drawable.hyd_fl);
            break;
        case "59":
            team2_name.setBackgroundResource(R.drawable.blr_fl);
            break;
        default:
            team1_name.setBackgroundResource(R.drawable.otherflag);
            // h_upcoming.tv_left.setText(str1);
            break;
        }

        return vi;

    }
}

      /*  private static class CustomViewGroup extends LinearLayout {

    // =============================================================================
    // Child views
    // =============================================================================

    private TextView textView;

    private ImageView imageView;

    private Button button;

    // =============================================================================
    // Constructor
    // =============================================================================

    private CustomViewGroup(Context context) {
        super(context);

        this.setOrientation(VERTICAL);

        this.textView = new TextView(context);
        this.imageView = new ImageView(context);
        this.button = new Button(context);

        LinearLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        this.textView.setLayoutParams(layoutParams);
        this.imageView.setLayoutParams(layoutParams);
        this.button.setLayoutParams(layoutParams);

        this.textView.setGravity(Gravity.CENTER);

        this.imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        this.imageView.setAdjustViewBounds(true);

        this.button.setText("Goto GitHub");
        this.button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://davidschreiber.github.com/FancyCoverFlow"));
                view.getContext().startActivity(i);
            }
        });

        this.addView(this.textView);
        this.addView(this.imageView);
        this.addView(this.button);
    }

    // =============================================================================
    // Getters
    // =============================================================================

    private TextView getTextView() {
        return textView;
    }

    private ImageView getImageView() {
        return imageView;
    }
}*/

解决方案

find import android.view.ViewGroup.LayoutParams; this line and replace with import android.widget.LinearLayout.LayoutParams; this line

这篇关于java.lang.ClassCastException:android.view.ViewGroup $的LayoutParams不能转换为android.widget.Gallery $的LayoutParams的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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