<com.aa.bb.cc.widget.PageWidget android:id="@+id/cendpage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />


class PageWidget extends LinearLayout implements OnClickListener
{
private OnTurnPageListener mListener;

private int mCurrPage = 0;

private int mTotalPage = 0;

public PageWidget(Context context, AttributeSet attrs)
{
super(context, attrs);

this.addView(LayoutInflater.from(context).inflate(R.layout.split_pages, null));
}

protected void onFinishInflate()
{
this.setVisibility(GONE);
findViewById(R.id.prePage).setOnClickListener(this);
findViewById(R.id.nextPage).setOnClickListener(this);
findViewById(R.id.lastPage).setOnClickListener(this);
findViewById(R.id.firstPage).setOnClickListener(this);
}

/**设置数据
* @param totalPage 总页数
* @param currPage 当前页
*/
public void setData(int totalPage, int currPage)
{
this.mTotalPage = totalPage;
this.mCurrPage = currPage;
if (totalPage <= 0 || currPage <= 0)
{
this.setVisibility(GONE);
}
else
{
this.setVisibility(VISIBLE);
TextView percent = (TextView)findViewById(R.id.percent);

percent.setText(MessageFormat.format(getResources().getString(R.string.page_percent), new Object[] {
currPage + "", totalPage + ""}));
}
}

public void onClick(View v)
{
switch (v.getId())
{
case R.id.prePage:
if (mCurrPage > 1)
{
mCurrPage -= 1;
if (mListener != null)
{
mListener.onClick(v, mCurrPage, mTotalPage);
}
}

break;
case R.id.nextPage:
if (mCurrPage < mTotalPage)
{
mCurrPage += 1;
if (mListener != null)
{
mListener.onClick(v, mCurrPage, mTotalPage);
}
}
break;
case R.id.lastPage:
mCurrPage = mTotalPage;
if (mListener != null)
{
mListener.onClick(v, mCurrPage, mTotalPage);
}
break;
case R.id.firstPage:
mCurrPage = 1;
if (mListener != null)
{
mListener.onClick(v, mCurrPage, mTotalPage);
}
break;
default:
break;
}
}

public interface OnTurnPageListener
{
/**监听类方法
* @param v 被点击的试图
* @param currPage 点击后产生的页数
* @param totalPage 总页数
*/
void onClick(View v, int currPage, int totalPage);

}

/**设置跳转下载数据的接口
*/
public void setOnTurnPageListener(OnTurnPageListener pageListener)
{
this.mListener = pageListener;
}

public void setCurrPage(int currPage)
{
mCurrPage = currPage;
}

public int getCurrPage()
{
return mCurrPage;
}

}

更多相关文章

  1. Android自动补全(二)
  2. Android常用代码
  3. Android中自定义Dialog样式
  4. Android(安卓)深入研究LBS(基于位置的服务)
  5. Android:霓虹灯
  6. 修改进度条ProgressBar颜色
  7. Android颜色渐变的分隔线(ListView)
  8. Android中全屏设置
  9. Android(安卓)深入研究LBS(基于位置的服务)

随机推荐

  1. 常用的报表工具有哪些_目前最流行的报表
  2. 国外有Tableau,国内有思迈特软件Smartbi
  3. 应用计量经济学现状: 因果推断与政策评估
  4. iOS发开之如何成为一名高手?
  5. python+opencv实现连通区域分离
  6. Linux运维入门教程06-01 (系统的初始化和
  7. Python关于 物理实验数据的代码简化处理
  8. 索引不是越多越好,理解索引结构原理,才有助
  9. Python中的图像增强技术
  10. 基于Logstash+Zabbix4.4做主机登录失败监