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,不知有没有其它的办法。

  • 相关阅读:
    500 cannot be cast to javax.xml.registry.infomodel
    mybatis
    [Nest] 02.nest之控制器
    [React] react-interview-01
    [JavaScript] es6规则总结
    [JavaScript] Date对象
    [Vue] vuex-interview
    [Vue] vue-router-interview
    [Vue] vue的一些面试题4
    [Vue] vue的一些面试题3
  • 原文地址:https://www.cnblogs.com/atwind/p/4521932.html
Copyright © 2011-2022 走看看