org.xutils.view.ViewFinder

package org.xutils.view;



import android.app.Activity;

import android.view.View;



/**

* @author 注释者:王教成

* @version 注释版:1.0.0

* 视图获取器

*/

/*package*/ final class ViewFinder {

private View view;

   private Activity activity;

   public ViewFinder(View view) {

this.view = view;

   }//构造器:初始化View

   public ViewFinder(Activity activity) {

this.activity = activity;

   }//构造器:初始化Activity



   /**

    * 通过ID获取View或Activity

    * @param id 视图组件ID

    * @return 返回view、activity或null

    */

   public View findViewById(int id) {

if (view != null) return view.findViewById(id);

       if (activity != null) return activity.findViewById(id);

       return null;

   }

/**

    * 通过ViewInfo对象获取视图组件

    * @param info ViewInfo视图信息对象

    * @return 返回视图组件

    */

   public View findViewByInfo(ViewInfo info) {

return findViewById(info.value, info.parentId);

   }

/**

    * 通过ID和父视图ID获取视图组件

    * @param id 视图组件ID

    * @param pid 父视图组件ID

    * @return 返回视图组件

    */

   public View findViewById(int id, int pid) {

View pView = null;

       if (pid > 0) {

pView = this.findViewById(pid);//父视图ID大于0返回pView父视图

       }

View view = null;

       if (pView != null) {

view = pView.findViewById(id);//pView父视图非空,通过pView父视图对象根据id获得view

       } else {

view = this.findViewById(id);//pView父视图为空,通过本对象根据id获取view

       }

return view;//返回view

   }

/*public Context getContext() {

       if (view != null) return view.getContext();//view非空,获取Context

       if (activity != null) return activity;//activity非空,返回activity

       return null;

   }*/

}

org.xutils.view.ViewFinder