<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;
}
}
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;
}
}