从片段访问不同布局的imageview

时间:2014-10-22 08:07:27

标签: android android-fragments imageview

我希望带有id R.id.guggu_media2的Image2在滚动时可见,带有ID为R.id.guggu_media的Image在滚动时不可见。Image和Image2是GugguAdapter.java的一部分,它具有layout_pager_image.xml布局。我的HomeFragment.java有不同的布局,我想访问不同布局的imageview。这有可能吗?同样根据我的项目,Image和Image2都不能在GugguAdapter.java._h通过_getViewForAudioMedia()方法中的_getViewForAudioMedia()之外声明我是播放音频,如果用户滚动我暂停音频。但我也希望图像按钮在滚动时从播放(R.id.guggu_media)更改为暂停(R.id.guggu_media2)..

HomeFragment.java

  public class HomeFragment extends Fragment implements OnRefreshListener {
               @Override
                public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                         Bundle savedInstanceState) {
             homeFragmentView = inflater.inflate(R.layout.fragment_guggu_moments, container, false);
              public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {


                    }

                    public void onScrollStateChanged(AbsListView view, int scrollState) {


                       GugguApplication.getInstance().cleanUp(mVisulizerView);



                    }
                });
         return homeFragmentView;
            }

GugguAdapter.java

    public void _getViewForAudioMedia(int position,final GugguMoment lMoment, View convertView)
    {
final VisualizerView     lVisualizerView = (VisualizerView) convertView.findViewById(R.id.visualizerView);
  final ImageView Image = (ImageView) convertView.findViewById(R.id.guggu_media);
        final ImageView Image2 = (ImageView) convertView.findViewById(R.id.guggu_media2);


        if (!mIsAudioPlaying) {

            Image.setVisibility(View.VISIBLE);
            Image2.setVisibility(View.INVISIBLE);
        }
        else
        {
            Image2.setVisibility(View.VISIBLE);
            Image.setVisibility(View.INVISIBLE);
        }

            convertView.findViewById(R.id.guggu_image).setVisibility(View.INVISIBLE);
            convertView.findViewById(R.id.guggu_video).setVisibility(View.INVISIBLE);

            final ProgressBar lAudioProgressBar = (ProgressBar) convertView.findViewById(R.id.guggu_video_progress);
            lAudioProgressBar.setVisibility(View.INVISIBLE);

            Image.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view)
                {
                    lVisualizerView.setVisibility(View.VISIBLE);
                    GugguApplication.getInstance().cleanUp(lVisualizerView);
                    GugguApplication.getInstance().initTunnelPlayerWorkaround(mCtxt);
                    GugguApplication.getInstance().init(mCtxt, lMoment.getGugguMediaLoc(), lVisualizerView, lAudioProgressBar);
                    Image.setVisibility(View.INVISIBLE);
                   Image2.setVisibility(View.VISIBLE);
                    mIsAudioPlaying = true;

                }

            });
        Image2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view)
            {
                Image.setVisibility(View.VISIBLE);
                Image2.setVisibility(View.INVISIBLE);
                GugguApplication.getInstance().cleanUp(lVisualizerView);
            }

        });
            lVisualizerView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mIsAudioPlaying)
                    {
                        Image.setVisibility(View.VISIBLE);
                        Image2.setVisibility(View.INVISIBLE);
                        GugguApplication.getInstance().cleanUp(lVisualizerView);
                    }
                }

            });
        }

0 个答案:

没有答案