zoukankan      html  css  js  c++  java
  • 在JazzyViewPager中调用其它layout布局xml并使用

    开源地址:https://github.com/jfeinstein10/JazzyViewPager

    发现网上的例子使用的是直接创建的一个TextView来做的。但是实际上使用,不可能只有这一个控件。

    下面是我的实现方式,如果大家有更好的方法,麻烦告之。不胜感激~~~

    在自定义的

    MainAdapter extends PagerAdapter
      + public Object instantiateItem(ViewGroup container, final int position) { 方法中的部分代码实现如下:

     View currView = null;
     LayoutInflater factory = LayoutInflater.from(context);
    currView = factory.inflate(getLayoutId(), null);
    
    //获取控件内容并设定click侦听
    final RelativeLayout btnDebug = (RelativeLayout) currView.findViewById(R.id.btnDebug);
            Log.d("MainAdapter", "Button is null ?" + (btnDebug == null));
            if (btnDebug != null) btnDebug.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.d("DEBUG", "CLICK ME.");                
                }
            });
    
    container.addView(currView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    jazzyPager.setObjectForPosition(currView, position);
    return currView;

    即,要通过代码的方式来实现载入layout中的布局XML,不知有没有其它的办法。

  • 相关阅读:
    swift 加载 storyboard 里的UIViewController
    ios 下创建,删除文件夹的方法
    iOS ARC模式 内存管理
    UISwitch
    建立 svn 服务端
    去除NSString里面的空格
    正则表达式验证邮箱的合法性
    memcached 的安装与使用
    windows2008 IIS下配置FTP服务
    lua语法备忘录
  • 原文地址:https://www.cnblogs.com/atwind/p/4521932.html
Copyright © 2011-2022 走看看