for (int i = 0; i < layout.getChildCount(); i++) {
View layout = layout.getChildAt(i);
if (layout instanceof LinearLayout) {
LinearLayout ll = (LinearLayout) layout;
int layoutCount = ll.getChildCount();
for (int j = 0; j < layoutCount; j++) {
View cv=(View)ll.getChildAt(j);
if(cv instanceof TextView){
cv.setOnClickListener(linstener);
}
}
}
}
第一个for循环遍历所有的子view
如果子view是一个布局,则第二个for循环遍历其子view
2.三种方法获取LayoutInflater对象:
1) 由LayoutInflater的静态函数:from(Context context) 获取:
static LayoutInflater from(Context context);
LayoutInflater inflater = LayoutInflater.from(this);
View view=inflater.inflate(R.layout.ID, null);
//或写成:
View view=LayoutInflater.from(this).inflate(R.layout.ID, null);
2) 由服务获取:
LayoutInflater inflater = (LayoutInflater)context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
调用Activity的getLayoutInflater() 函数获取LayoutInflater 对象。
3.自定义控件onMeasure方法中MeasureSpec.getMode(widthMeasureSpec)返回的Mode值
如果向自定义控件添加的子view是fill_parent的话,返回android.view.View.MeasureSpec.UNSPECIFIED
如果向自定义控件添加的子view是wrap_content的话,返回android.view.View.MeasureSpec.AT_MOST
如果向自定义控件添加的子view指定了大小的话,返回android.view.View.MeasureSpec.EXACTLY
4.Layout gravity我的理解是当前组件对父组件的位置,而gravity是当前组件的内容对当前组件的位置。
5.在继承一些adapter时候,重写getview方法,
if (convertView == null) {
LayoutInflater layoutInflater = getLayoutInflater();
convertView = layoutInflater.inflate(R.layout.account_entry, parent, false);
}
可以利用convertView.findViewById方法,获取account_entry布局中的控件。最后返回convertView。
6.However, instead of applying an OnClickListener
to the button in your activity, you can assign a method to your button in the XML layout, using the android:onClick
attribute.这句话的意思是,代替activity中button的OnClickListener方法,你可以在XML布局的button属性里注册个方法,使用android:onClick属性。如下:
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/self_destruct"
android:onClick="selfDestruct" />
在activity中在写:
public void selfDestruct(View view) {
// Kabloey
}
7.android 连接sharepoint http://www.robertkuzma.com/2011/07/manipulating-sharepoint-list-items-with-android-java-and-ntlm-authentication/