1

我有一个 ListView,它在位置 0 处包含 ViewFlipper。但我无法使用 showNext 或 showPrevious 它没有效果。

下面的代码片段显示了我如何实例化 viewFlipper

            View view1 = inflater.inflate(R.layout.flipper, null); 
            viewFlipper=(ViewFlipper)view1.findViewById(R.id.flipper);

            viewFlipper.addView(getChildView(v1,0),0);
            viewFlipper.addView(getChildView(v2,1),1);
            viewFlipper.addView(getChildView(v3,2),2);
            viewFlipper.addView(getChildView(v4,3),3);
            viewFlipper.addView(getChildView(v5,4),4);

            viewFlipper.setOnTouchListener(new OnTouchListener() {
                @Override
                public boolean onTouch(final View view, final MotionEvent event) {
                    gdt.onTouchEvent(event);
                    return true;
                }
            });

这是方法 getChildView

private View getChildView(View view,int index){
    LayoutInflater inflater = this.getLayoutInflater();

    view = inflater.inflate(R.layout.event_feed, null);      
    //Event Highlight
    highlight=(LinearLayout)view.findViewById(R.id.highlight);
    media_url_value=(ImageView)view.findViewById(R.id.slider_pic);
    slider_pic1=(ImageView)view.findViewById(R.id.slider_i1);
    slider_pic2=(ImageView)view.findViewById(R.id.slider_i2);
    slider_pic3=(ImageView)view.findViewById(R.id.slider_i3);
    slider_pic4=(ImageView)view.findViewById(R.id.slider_i4);
    slider_pic5=(ImageView)view.findViewById(R.id.slider_i5);
    title_value=(TextView)view.findViewById(R.id.slider_title);
    info_value=(TextView)view.findViewById(R.id.slider_info);
    event_date_value=(TextView)view.findViewById(R.id.slider_eventdate);

    imageLoader.DisplayImage(media_url[index],EventList.this,media_url_value);
    title_value.setText(title[index]);

    if(info[index].length()>=120)
        info_value.setText(info[index].substring(0,120)+"......");
    else
        info_value.setText(info[index]);

    event_date_value.setText(event_date[index]);

    if(index==0){
        slider_pic1.setBackgroundResource(R.drawable.slider_hover);
        slider_pic2.setBackgroundResource(R.drawable.slider_empty);
        slider_pic3.setBackgroundResource(R.drawable.slider_empty);
        slider_pic4.setBackgroundResource(R.drawable.slider_empty);
        slider_pic5.setBackgroundResource(R.drawable.slider_empty);
    }

    if(index==1){
        slider_pic1.setBackgroundResource(R.drawable.slider_empty);
        slider_pic2.setBackgroundResource(R.drawable.slider_hover);
        slider_pic3.setBackgroundResource(R.drawable.slider_empty);
        slider_pic4.setBackgroundResource(R.drawable.slider_empty);
        slider_pic5.setBackgroundResource(R.drawable.slider_empty);
    }

    if(index==2){
        slider_pic1.setBackgroundResource(R.drawable.slider_empty);
        slider_pic2.setBackgroundResource(R.drawable.slider_empty);
        slider_pic3.setBackgroundResource(R.drawable.slider_hover);
        slider_pic4.setBackgroundResource(R.drawable.slider_empty);
        slider_pic5.setBackgroundResource(R.drawable.slider_empty);
    }

    if(index==3){
        slider_pic1.setBackgroundResource(R.drawable.slider_empty);
        slider_pic2.setBackgroundResource(R.drawable.slider_empty);
        slider_pic3.setBackgroundResource(R.drawable.slider_empty);
        slider_pic4.setBackgroundResource(R.drawable.slider_hover);
        slider_pic5.setBackgroundResource(R.drawable.slider_empty);
    }

    if(index==4){
        slider_pic1.setBackgroundResource(R.drawable.slider_empty);
        slider_pic2.setBackgroundResource(R.drawable.slider_empty);
        slider_pic3.setBackgroundResource(R.drawable.slider_empty);
        slider_pic4.setBackgroundResource(R.drawable.slider_empty);
        slider_pic5.setBackgroundResource(R.drawable.slider_hover);
    }

    return view;
}

视图翻转器的 getDisplayedChild() 始终返回 0,尽管它正在视图之间翻转。

任何帮助将不胜感激... :)

4

1 回答 1

0

您是否尝试过清理项目(Eclipse->Project->Clean..)?有时是 R.java 导致了这个问题。

于 2012-10-27T10:03:10.220 回答